构造函数参数问题C++
Constructor Parameter issue C++
我有一个类的构造函数,它接受布尔值、数组指针和字符串。
TheConstructor(bool theBool=true, int *theArray=0, std::string message="0");
这是在头文件中写入它的正确方法吗?我的程序现在没有编译,因为"对"构造函数"和其他成员函数的未定义引用"。
这也可能导致这种情况的原因是什么?我检查了一下,在main中.cpp我 #included"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)
{
}
未指定第一个参数的名称,但这可能不会导致您遇到的错误:
TheConstructor(bool=0, int *theArray=0, std::string message="0");
您可能想执行以下操作:
TheConstructor(bool flag=0, int *theArray=0, std::string message="0");
但是,如果没有看到定义,我无话可说。仅仅通过查看声明很难预测还有什么问题。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题