实现构造函数时出现LNK2019错误
Error LNK2019 while implementing a constructor
我在构造函数的实现上遇到了一些麻烦,我无法找出问题所在。我花了很多时间研究这个问题,如果你能给我一些建议,我会很感激的。
主代码为:
#include "stdafx.h"
#include "Rocket.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
Rocket* rocket;
rocket=new Rocket();
//LLA* position=rocket->positionLLA;
return 0;
}
Rocket.h
#pragma once
#include "LLA.h"
class Rocket {
public:
Rocket(); // Default constructor
LLA* positionLLA;
};
Rocket.cpp
#include "stdafx.h"
#include "Rocket.h"
#include <iostream>
using namespace std;
Rocket::Rocket() // Default constructor
{
// Initialise the position
positionLLA=new LLA();
}
错误提示:
error LNK2019: unresolved external symbol "public: __thiscall Rocket::Rocket(void)" (??0Rocket@@QAE@XZ) referenced in function _main.
我知道这个错误与没有声明变量有关,但是我认为我已经声明了所有的类和构造函数。
PS:我使用Visual Studio 2008是为了添加依赖项。
我假设LLA在你的。h文件中是正确定义的
你正在编译Rocket.cpp到Rocket。O和main.cpp成main。然后将两个目标文件链接在一起?
您的错误似乎暗示链接器无法从Rocket获取符号信息。o,通常意味着火箭。0未找到
哦,作为一个细节,因为Rocket使用的是LLA*,你不需要在Rocket.h中包含LLA.h,你可以简单地向前声明
class LLA;
您可能希望将#ifndef
, #define
和#endif
添加到您的头文件中。在不同的文件中包含多个相同的内容可能会导致复杂性。
相关文章:
- 链接CPP文件进行测试时发生LNK2019错误
- 32位到64位:LNK2019错误,如何检索相关信息
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 尝试使用 TMXlite 编译项目时LNK2019错误
- LNK2019错误;此处缺少/未定义的内容
- DX11 DirectInput8创建引起LNK2019错误
- C++ mysql 仅在构建解决方案时LNK2019错误
- C LNK2019错误,未解决的外部字符
- C++ 带有出现LNK2019错误的对象的链接列表
- 解决 main 中的LNK2019错误
- 尝试使用命名空间中的函数时LNK2019错误
- LNK2019错误未解析的外部符号
- LNK2019错误,在Visual Studio 2012 C++的main中使用的函数
- 同一项目中两个类之间的visual c++LNK2019错误
- LNK2019错误(未解析的外部符号)将SQLite链接到DLL
- C++/CLI 包装器LNK2028和LNK2019错误
- LNK2019错误,尝试覆盖运算符<< 对于 LinkedList 类
- LNK2001和LNK2019错误 - DirectX 未解析的外部符号
- (2012)Visual C++LNK2019错误,可能是模板问题
- LNK2019错误一个DLL链接到MFC DLL