模板类"unresolved external symbal"
"unresolved external symbal" on template class
我已经在同一个问题上工作了三天,我对此无能为力。 请帮忙!!
这不是具有相似名称的问题的重复。 名称相似,但问题完全不同。
可能与外部依赖关系有关,这是我被告知的。
我正在发布我的所有代码,如果我需要发布更多信息,请询问!
list_test.cpp
这做得更多,但这就是它搞砸的地方。
#include <cctype> // Provides toupper
#include <iostream> // Provides cout and cin
#include <cstdlib> // Provides EXIT_SUCCESS
#include "list.h" // With value_type defined as double
#include "Node.h"
#include "Iterator.h"
using namespace std;
using namespace list_1;
int main( )
{
list<double> test;
}
iterator.h
// Template CLASS PROVIDED: Iterator
#pragma once
#include "Node.h"
namespace list_1
{
template<typename T>
class Iterator
{
public:
Iterator<T> (Node<T> *np);
// precondition: is_item is true
// post condition n points to the next item in the list
void operator++();
// precondition:
// postcondition: returns true if there is a valid item
bool is_item();
// precondition: is_item == true
// postcondition returns data that n is pointing at
T operator* ();
private:
Node<T>* n;
};
template<typename T>
Iterator<T>::Iterator (Node<T> *np)
{
n = np;
}
template<typename T>
void Iterator<T>::operator++()
{
assert(is_item( ) == true);
n = n->next;
}
template<typename T>
bool Iterator<T>::is_item()
{
return (n->data != NULL);
}
template<typename T>
T Iterator<T>::operator* ()
{
assert(is_item( ) == true);
return n->data;
}
}
Node.h
#pragma once
namespace list_1
{
template <typename T>
struct Node
{
T data;
Node<T> *next;
// Constructor
// Postcondition:
Node<T> (T d);
};
template <typename T>
Node<T>::Node(T d)
{
data = d;
next = NULL;
}
}
list.h
#include "Node.h"
#include "Iterator.h"
namespace list_1
{
template <typename T>
class list
{
public:
// CONSTRUCTOR
list();
// postcondition: all nodes in the list are destroyed.
~list();
// MODIFICATION MEMBER FUNCTIONS
//postcondition: entry is added to the front of the list
void insert_front(const T& entry);
//postcondition: entry is added to the back of the list
void add_back(const T& entry);
// postcondition: all nodes with data == entry are removed from the list
void remove_all(const T& entry);
// postcondition: an iterator is created pointing to the head of the list
Iterator<T> begin(void);
// CONSTANT MEMBER FUNCTIONS
// postcondition: the size of the list is returned
int size( ) const;
private:
Node<T>* head;
};
template <typename T>
list<T>::list( )
{
head = NULL;
}
template <typename T>
list<T>::~list()
{
}
template <typename T>
void list<T>::insert_front(const T& entry)
{
// head = new node(entry, head);
}
template <typename T>
void list<T>::add_back(const T& entry)
{
}
template <typename T>
void list<T>::remove_all(const T& entry)
{
}
template <typename T>
Iterator<T> list<T>::begin(void)
{
//Iterator<T> traverse( );
//return traverse;
}
template <typename T>
int list<T>::size( ) const
{
int size = 0;
Node<T> *tempPoint = head;
for (tempPoint = head; tempPoint != NULL; tempPoint = tempPoint->next)
{
size ++;
}
return size;
}
}
以下是错误消息:
1>------ Build started: Project: CS2420LinkedList, Configuration: Debug Win32 ------
1>list_test.obj : error LNK2019: unresolved external symbol "public: __thiscall list_1::list<double>::~list<double>(void)" (??1?$list@N@list_1@@QAE@XZ) referenced in function _main
1>list_test.obj : error LNK2019: unresolved external symbol "public: __thiscall list_1::list<double>::list<double>(void)" (??0?$list@N@list_1@@QAE@XZ) referenced in function _main
1>C:UsersKyleYasDocumentsVisual Studio 2010ProjectsCS2420LinkedListDebugCS2420LinkedList.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我不一定会为它的使用辩护,但我认为你的问题不是using
陈述。当你不#include <list>
时,我看不出有任何理由发生碰撞.那就是:error C2872: 'list' : ambiguous symbol...
.
从消息中的内容来看,我将首先确保list.h
是它应该在的地方。
始终可以引用 VS 错误代码,例如您获得的LNK2019,并根据问题检查示例。
谢谢你的回答! 我发现了问题。 我在外部依赖项中有两个相同的 list.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
- Android Studio External Native Build 预编译标头
- 在 R 中调用"multi file C++ code with external libraries referenced"
- 尝试使用 CPP 构建类时"unresolved external..."
- 通过覆盖虚拟函数来获取'unresolved external symbol'
- 运行时动态加载库时出错"unresolved external symbol"
- 如何从输入中定义的"external" int 定义结构中的数组大小
- 为什么 VS C++链接器返回具有混合 DLL 转发的"LNK2001: unresolved external symbol"?
- Visual Studio 2017 中的 MySQL 连接器/C++ 错误"Unresolved external symbol _get_driver_instance"
- 如何清理本地引用中跟踪C++对象<External>?
- 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
- "error LNK2019: unresolved external fatal"和"error LNK1120: 1 unresolved externals"
- 模板类"unresolved external symbal"