班级没有成员“班级", [英] Class has no member "Class"
问题描述
我正在尝试创建一个名为 Drone
的类,并且有两个文件,分别是 Drone.h
和 Drone.cpp
.
I am trying to create a class called Drone
, and have two files, Drone.h
and Drone.cpp
.
Drone.h
class Drone {
protected:
void foo();
};
Drone.cpp
#include "Drone.h"
Drone::Drone() // <---ERROR
{
}
void Drone::foo()
{
}
我得到了错误:
无人机"类没有成员Drone."
"Class 'Drone' has no member Drone."
当我将鼠标悬停在Drone上时,工具提示中的
.在编译器中,它给出错误:
in the tooltip as I hover over Drone. In the compiler, it gives the error:
错误C2600:'Drone :: Drone':无法定义编译器生成的特殊成员函数(必须首先在类中声明)
error C2600: 'Drone::Drone' : cannot define a compiler-generated special member function (must be declared in the class first)
这是为什么?我要做的就是为Drone创建一个构造器.
Why is this? All I am trying to do is make a constructor for Drone.
推荐答案
您尚未在头文件中明确声明默认构造函数:
You have not explicitly declared a default constructor in your header file:
class Drone {
protected:
void foo();
public:
Drone(); // <----
};
必须先声明每个成员函数(包括构造函数和运算符),然后才能指定定义.
Every member function, including constructors and operators, must be declared before a definition can be specified.
这篇关于班级没有成员“班级",的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!