我有一个构造函数,用于接收布尔值,指向数组的指针和字符串的类。

TheConstructor(bool theBool=true, int *theArray=0, std::string message="0");


这是将其写入头文件中的正确方法吗?由于“对“构造函数”和其他成员函数的未定义引用”,我的程序现在无法编译。

还有什么原因造成的呢?我检查并在main.cpp中,我#include“ Class.h”并定义了我在“ Class.cpp”中编写的“ Class.h”中声明的每个需要定义的成员函数。

最佳答案

我希望您不要为类TheConstructor命名:)如果您有类C,则几乎可以像声明类一样声明其构造函数-您忘记了输入bool参数的名称:

C.h:

#include <string>

class C
{
public:
    C(bool b = 0, int *theArray = 0, std::string message = "0");
};


C.cpp:

#include "C.h"
C::C(bool b, int *theArray, std::string message)
{

}

07-24 09:46
查看更多