尝试编译项目时"unresolved external symbol"错误C++
"unresolved external symbol" error when trying to compile C++ project
我试图实现几个类,但我得到了编译代码时的以下错误。我试图删除所有多余的代码,但没有一个帮助。我不知道哪里出错了。
下面是我编译代码时得到的错误:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: __thiscall FullArray<int>::FullArray<int>(unsigned int)" (??0?$FullArray@H@@QAE@I@Z) referenced in function _wmain FinancialDerivatives C:UsersJeremy NguyenDocumentsVisual Studio 2015ProjectsFinancialDerivativesFinancialDerivativesFinancialDerivatives.obj 1
Error LNK1120 2 unresolved externals FinancialDerivatives C:UsersJeremy NguyenDocumentsVisual Studio 2015ProjectsFinancialDerivativesDebugFinancialDerivatives.exe 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall FullArray<int>::~FullArray<int>(void)" (??1?$FullArray@H@@UAE@XZ) referenced in function _wmain FinancialDerivatives C:UsersJeremy NguyenDocumentsVisual Studio 2015ProjectsFinancialDerivativesFinancialDerivativesFinancialDerivatives.obj 1
FullArray.h文件:
#pragma once
#include <vector>
template <class V>
class FullArray
{
private:
std::vector<V> m_vector; // Use STL vector class for storage
public:
// Constructors & destructor
FullArray();
FullArray(size_t size);
FullArray(const FullArray<V>& source);
FullArray<V>& operator = (const FullArray<V>& source);
virtual ~FullArray();
};
FullArray.cpp文件:
#include "stdafx.h"
#include "FullArray.h"
template<class V>
FullArray<V>::FullArray()
{
m_vector = std::vector<V>(1); // vector object with 1 element
}
template<class V>
FullArray<V>::FullArray(size_t size)
{
m_vector = std::vector<V>(size);
}
template<class V>
FullArray<V>::FullArray(const FullArray<V>& source)
{
m_vector = source.m_vector;
}
template<class V>
FullArray<V>& FullArray<V>::operator=(const FullArray<V>& source)
{
// Exit if same object
if (this == &source) return *this;
// Call base class constructor
//ArrayStructure<V>::operator = (source);
// Copy the embedded vector
m_vector = source.m_vector;
return *this;
}
template<class V>
FullArray<V>::~FullArray()
{
}
主要文件:#include "stdafx.h"
#include "FullArray.h"
int _tmain(int argc, _TCHAR* argv[])
{
FullArray<int> tmp(5);
return 0;
}
如果您编译模板,则需要在使用模板的任何地方都可以获得源代码,因此将。cpp文件包含在。h文件的底部,或者包含。cpp文件而不是。h文件。
相关文章:
- CppSQLite 抛出"LNK2019: unresolved external symbol"错误
- Visual Studio中的wxwidgets应用程序给出错误"LNK2019 unresolved external symbol"
- 在 C++ 中嵌入 V8 会导致与 libcpp 相关的"unrecognized external symbol"错误
- 我的游戏引擎的 spdlog 日志记录出现奇怪的"unresolved external symbol"错误
- 如何修复"unresolved external symbol _gladLoadGLLoader referenced in function _main"和"unresolved external
- 通过覆盖虚拟函数来获取'unresolved external symbol'
- 运行时动态加载库时出错"unresolved external symbol"
- 为什么 VS C++链接器返回具有混合 DLL 转发的"LNK2001: unresolved external symbol"?
- Visual Studio 2017 中的 MySQL 连接器/C++ 错误"Unresolved external symbol _get_driver_instance"
- CMake 和 Visual Studio 出现"unresolved external symbol"错误
- DLL 注入编译 "unresolved external symbol" Visual Studio C++
- "Error LNK2001: unresolved external symbol _main"仍然存在
- QT 单元测试 moc "unresolved external symbol" for QMetaObject
- 主外部功能的C++ "unresolved external symbol"
- 错误 : "error LNK2019: unresolved external symbol"
- 为什么我的代码生成"Unresolved external symbol"错误?
- 使用三角形库时的"unresolved external symbol _triangulate"
- 如何修复" Error LNK2019 : unresolved external symbol ... "
- 问题:"error LNK2019: unresolved external symbol"
- 为什么我会收到"unresolved external symbol"消息?