c++对类构造函数的未定义引用
c++ undefined refernce to class constructer
//Header FILE:
#ifndef BMI_H_INCLUDED
#define BMI_H_INCLUDED
#include<iostream>
#include<string>
using namespace std;
class BMI{
public:
//default constructer
BMI();
//overloaded
BMI(string,int,double);
private:
string newName;
int newHeight;
double newWeight;
};
#endif // BMI_H_INCLUDED
//Implementation file:
#include "BMI.h"
BMI ::BMI(){
newHeight=0;
newWeight=0.0;
}
BMI::BMI(string name,intheight,double weight){
newName=name;
newHeight=height;
newWeight=weight;
}
//Main file:
#include <iostream>
#include<string>
#include "BMI.h"
using namespace std;
int main()
{
string name;
int height;
double weight;
cout<<"Name:n";
getline(cin,name);
cout<<"Height(Inches):n";
cin>>height;
cout<<"Weight(Pounds):";
cin>>weight;
BMI person_1("John",89,90.0);
//I get the error on the above line error is //undefinedreferenceto`BMI::BMI(std::string, int, double)'
}
有人知道为什么这种事一直发生在我身上吗?
我使用代码块,如果是这样,我该如何修复并防止它再次发生。
每当我将类分离为头文件和cpp文件时,就会发生这种情况。这只是我的程序因此而多次编译失败的一次。
在BMI::BMI(string name,intheight,double weight){
中,int和height之间没有空格。
这导致BMI person_1("John",89,90.0);
引用了一个不存在的构造函数。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用