构造函数参数问题C ++ [英] Constructor Parameter issue C++
问题描述
我有一个类的构造函数接受一个bool,指向数组和字符串的指针。
I have a constructor for a class that takes in a bool, a pointer to an array, and string.
TheConstructor(bool theBool=true, int *theArray=0, std::string message="0");
这是否正确的方式写入头文件?我的程序现在不是编译,因为一个未定义的引用构造函数和其他成员函数。
Is this the correct way to write it in the header file? My program isn't compiling right now because of a "undefined reference to "the constructor" and to other member functions".
这可能是什么原因?我检查和在main.cpp我#includedClass.h和定义每一个需要定义的成员函数,在Class.h中写的Class.cpp
What could be causing this also? I checked and in main.cpp I #included "Class.h" and defined every memberwise function that needed to be defined that was stated in "Class.h" I wrote in "Class.cpp"
推荐答案
我希望你没有命名你的类 TheConstructor
:)如果你有< c> C 你可以声明它的构造函数几乎与你一样 - 你忘了放置 bool
参数的名称:
I hope you didn't name your class TheConstructor
:) If you have class C
you can declare its constructor almost as you did - you forgot to put the name of the bool
argument:
Ch:
#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)
{
}
这篇关于构造函数参数问题C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!