为什么 =default on 运算符 = 在有 const 成员时编译
Why does =default on operator= compile when there is a const member?
class Foo {
public:
Foo& operator=(const Foo&) = default;
private:
const int i = 0;
};
为什么=default
允许那里?它编译时没有错误。我认为=default
应该失败,因为它不可能分配给const
变量?
到底发生了什么?
当函数无法生成时(在这种情况下),= default
将生成它作为 = delete
d 代替。如果尝试使用该赋值运算符,编译器应生成错误。
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 访问条件类成员的方法不仅在被调用时才编译
- 为什么下面的模板化类成员函数无法编译?
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 为什么传递非静态成员函数会导致编译错误?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 是否可以在编译时初始化对象的 C 样式函数指针,以便它调用对象的成员函数?
- c++ 是否保证标头初始化的静态 const 成员跨编译单元和库共享单个实例?
- 在C++中,成员函数在编译时可用吗
- 当包含成员函数名为errno和cerrno时,g++7编译错误
- C++模板-基于参数编译成员函数
- 有一个可迭代的容器,其中的成员在编译时是已知的
- 使用成员函数创建std::函数不会编译
- 在VS2017中,我们如何在项目成员之间共享编译设置
- 如何在类成员函数中获得类似printf中的编译警告
- 为什么 std::condition_variable 作为类成员会导致 std::thread 编译错误?
- 私有静态成员 - 编译错误?
- 模板化类的模板化成员编译失败.VC++ 有效,但 G++ 失败
- 无法从单独的.cpp使用模板化成员编译/链接类
- 绑定到boost::function类成员编译错误