对构造函数(c++)的未识别引用
Unidentified reference to constructor (c++)
我已经对这个错误进行了几天的研究和谷歌搜索,据我所知,这是c++中许多人的常见问题,我仍然没有找到这个错误的明确答案。我读过链接文件可以解决这个问题,但我可以找到任何示例代码来做到这一点。我很快就要完成这段代码了,我只需要从主文件中调用构造函数(或者只生成一个简单的对象),但我一直收到这个"对NamedStorm::NamedStorm()的未识别引用"错误,请帮忙。
MAIN.CPP
#include <iostream>
#include <string>
#include "NamedStorm.h"
using namespace std;
NamedStorm storm[2];
int main(){
// NamedStorm Chris("Chris", 70.0, "T.S.", 990.0);
// storm[0] = Chris;
return 0;
}
命名风暴.cpp
// CPP => Function definition
#include <string>
#include "NamedStorm.h"
using namespace std;
// Defining static variables
int NamedStorm::stormCount = 0;
// Constructor definition
NamedStorm::NamedStorm(std::string sName, double wSpeed, std::string sCat, double sPress){
stormName = sName;
windSpeed = wSpeed;
stormCategory = sCat;
stormPressure = sPress;
stormCount++;
}
NamedStorm::NamedStorm(std::string sName){
stormName = sName;
stormCount++;
}
NamedStorm::NamedStorm(){
stormName = sName;
stormCount++;
}
// Destructor definition
//NamedStorm::~NamedStorm(){}
// Get (Accessor) function definition
int NamedStorm::getStormCount(){
return stormCount;
}
double NamedStorm::getStormPressure(){
return stormPressure;
}
string NamedStorm::getStormCategory(){
return stormCategory;
}
string NamedStorm::getName(){
return stormName;
}
// Set (Mutator) function definition
void NamedStorm::displayOutput(){}
void NamedStorm::sortByNames(){}
void NamedStorm::getAverageStormPressure(){}
void NamedStorm::getAverageWindSpeed(){}
void NamedStorm::getWindSpeed(){}
NamedStorm.h
#ifndef NAMEDSTORM_H_INCLUDED
#define NAMEDSTORM_H_INCLUDED
// NEVER use using namespce in header, use std instead.
class NamedStorm{
private:
std::string stormName;
std::string stormCategory;
double maxWindSpeed;
double stormPressure;
static int stormCount;
public:
// Constructor
NamedStorm(std::string, double, std::string, double);
NamedStorm(std::string);
NamedStorm();
// Destructor
//~NamedStorm();
// Get functions
int getStormCount();
double getStormPressure();
double getWindSpeed();
std::string getStormCategory();
std::string getName();
// Set functions
static void displayOutput();
static void sortByNames();
static void sortByWindSpeed();
static void getAverageWindSpeed();
static void getAverageStormPressure();
};
#endif // NAMEDSTORM_H_INCLUDED
为什么默认构造函数的定义与NamedStorm::NamedStorm(std::string)
的定义相同?我会从纠正这一点开始。
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 提升 ASIO 无法识别计时器对象
- 如何在c++中使用引用实现类似python的行为
- 从udp接收帧对于人脸识别来说太慢
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- 模板类无法识别友元运算符
- c++r值引用应用于函数指针
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- Visual Studio 2010 单元测试:无法识别引用的项目类
- 对 glutInit 的未识别引用
- QT5对QinputDialog和Qmessagebox的未识别引用.错误
- 谷歌语音识别(cpp示例):对AssignDescriptors()的未定义引用
- 对C++中函数的未识别引用
- 对构造函数(c++)的未识别引用
- 编译时错误,参数被识别为引用
- 编译过程中未识别的引用错误