本文介绍了班级没有成员“班级",的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个名为 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上时,工具提示中的

.在编译器中,它给出错误:

in the tooltip as I hover over Drone. In the compiler, it gives the error:

这是为什么?我要做的就是为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.

这篇关于班级没有成员“班级",的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:32