Class没有会员"Class"
Class has no member "Class"
我正在尝试创建一个名为 Drone
的 class,并且有两个文件,Drone.h
和 Drone.cpp
。
Drone.h
class Drone {
protected:
void foo();
};
Drone.cpp
#include "Drone.h"
Drone::Drone() // <---ERROR
{
}
void Drone::foo()
{
}
我收到错误:
"Class 'Drone' has no member Drone."
当我将鼠标悬停在无人机上时出现在工具提示中。在编译器中,它给出错误:
error C2600: 'Drone::Drone' : cannot define a compiler-generated special member function (must be declared in the class first)
这是为什么?我要做的就是为 Drone 创建一个构造函数。
您还需要在 header 中声明您的构造函数:
class Drone {
public:
Drone();
protected:
void foo();
};
所有成员,包括构造函数,都需要在class定义中声明。您不能在其他地方添加成员。
您没有在头文件中明确声明默认构造函数:
class Drone {
protected:
void foo();
public:
Drone(); // <----
};
每个成员函数,包括构造函数和运算符,都必须先声明,然后才能指定定义。
创建对象后调用的第一个函数是同名的constructor
。
"Class 'Drone' has no member Drone."
^^^^^==>class ^^^^^===>constructor
在头文件中声明:
class Drone {
public:
Drone(); //decleared
protected:
void foo();
};
我正在尝试创建一个名为 Drone
的 class,并且有两个文件,Drone.h
和 Drone.cpp
。
Drone.h
class Drone {
protected:
void foo();
};
Drone.cpp
#include "Drone.h"
Drone::Drone() // <---ERROR
{
}
void Drone::foo()
{
}
我收到错误:
"Class 'Drone' has no member Drone."
当我将鼠标悬停在无人机上时出现在工具提示中。在编译器中,它给出错误:
error C2600: 'Drone::Drone' : cannot define a compiler-generated special member function (must be declared in the class first)
这是为什么?我要做的就是为 Drone 创建一个构造函数。
您还需要在 header 中声明您的构造函数:
class Drone {
public:
Drone();
protected:
void foo();
};
所有成员,包括构造函数,都需要在class定义中声明。您不能在其他地方添加成员。
您没有在头文件中明确声明默认构造函数:
class Drone {
protected:
void foo();
public:
Drone(); // <----
};
每个成员函数,包括构造函数和运算符,都必须先声明,然后才能指定定义。
创建对象后调用的第一个函数是同名的constructor
。
"Class 'Drone' has no member Drone."
^^^^^==>class ^^^^^===>constructor
在头文件中声明:
class Drone {
public:
Drone(); //decleared
protected:
void foo();
};