gpt4 book ai didi

c++ - 尝试编译 C++ 项目时出现 "unresolved external symbol"错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:30:26 25 4
gpt4 key购买 nike

<分区>

我正在尝试实现一些类,但在编译代码时出现以下错误。我试图删除所有冗余代码,但没有一个有帮助。我不知道出了什么问题。

这是我在编译代码时遇到的错误:

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:\Users\Jeremy Nguyen\Documents\Visual Studio 2015\Projects\FinancialDerivatives\FinancialDerivatives\FinancialDerivatives.obj 1
Error LNK1120 2 unresolved externals FinancialDerivatives C:\Users\Jeremy Nguyen\Documents\Visual Studio 2015\Projects\FinancialDerivatives\Debug\FinancialDerivatives.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:\Users\Jeremy Nguyen\Documents\Visual Studio 2015\Projects\FinancialDerivatives\FinancialDerivatives\FinancialDerivatives.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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com