我正在尝试定义编译器自动生成并导致编译错误的构造函数。这是我的代码:
class myclass
{
public:
void Test_Func()
{}
};
myclass::myclass()
{
}
编译器是否为上面的简单类做任何额外的事情。这是我在 MSVC 编译器中遇到的错误:
"error C2600: 'myclass::myclass' : cannot define a compiler-generated special member function (must be declared in the class first)"
最佳答案
合成构造函数既被声明又被定义。您可能不会自己定义它。
您必须声明自己的构造函数才能提供实现。
[special]
(2003 年措辞,12/1)说:
The default constructor (12.1), copy constructor and copy assignment operator (12.8), and destructor (12.4) are special member functions. The implementation will implicitly declare these member functions for a class type when the program does not explicitly declare them, except as noted in 12.1. The implementation will implicitly define them if they are used, as specified in 12.1, 12.4 and 12.8. Programs shall not define implicitly-declared special member functions.
关于c++ - 编译器不允许定义编译器生成的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6322573/