C++ 11x 检查 : how to implement const-variants?

标签 c++ c++11

在 C++ 11 之前,我经常需要实现两个非常相似的方法变体来处理类/结构的 const 和非常量使用场景:

struct my_struct_t{
     ....
     float_t& at( uint32_t row, uint32_t col)
     {
         return *(((float_t*)((uint8_t*)numbers+row*row_stride)) + col);
     }

     float_t const& at( uint32_t row, uint32_t col) const
     {
         return *(((float_t*)((uint8_t*)numbers+row*row_stride)) + col);
     }

};

这在 C++ 11 中改变了吗?

最佳答案


这在标准库中很明显(它仍然使用显式的 const 方法)。

关于C++ 11x 检查 : how to implement const-variants?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005717/

相关文章:

c++ - auto&& 将如何延长临时对象的生命周期?

c++ - 表达式不能作为函数使用,c++机器码函数

c++ - 删除传递给构造函数的对象指针导致错误

c++ - 什么是 "identifier associated by name lookup"?

c++ - 尝试将 Struct 指针传递给类时出错

c++ - auto 声明的变量有时是通过引用?

c++ - 如何从 char** 读取 cstrings?

c++ - Visual C++ 2008 中的类型推断

c++ - 从二进制文件中读取 std::string

c++ - 关闭套接字时防止 FIN_WAIT2