"error LNK2019: 无法解析的外部符号, 该符号在函数 _main 中被引用" 异常,有代码,求解答
"error LNK2019: 无法解析的外部符号, 该符号在函数 _main 中被引用" 错误,有代码,求解答
错误为:
1>1512.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall CQueue<int>::CQueue<int>(void)" (??0?$CQueue@H@@QAE@XZ),该符号在函数 _main 中被引用
1>D:\Visual Studio 2008\Projects\1512\Debug\1512.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>生成日志保存在“file://d:\Visual Studio 2008\Projects\1512\1512\Debug\BuildLog.htm”
1>1512 - 2 个错误,0 个警告
这是什么情况啊,求解答,雪地里跪等
------解决方案--------------------
构造函数和析构函数没有实现
#include <iostream>
#include <stack>
#include <string>
using namespace std;
template <typename T>
class CQueue
{
public:
CQueue(void);
~CQueue(void);
void appendTail(const T& node);
void deleteHead();
private:
stack<T> stack1;
stack<T> stack2;
};
template <typename T>
void CQueue<T>::appendTail(const T& node)
{
stack1.push(node);
}
template <typename T>
void CQueue<T>::deleteHead()
{
if (stack2.size() <= 0)
{
while (stack1.size() > 0 )
{
T& data = stack1.top();
stack1.pop();
stack2.push(data);
}
if (stack2.size() == 0)
{
cout << "-1" << endl;
}
else
{
T head = stack2.top();
cout << head << endl;
stack2.pop();
delete &head;
}
}
}
int main(void)
{
int n = 0;
while (cin >> n)
{
CQueue<int>* cQueue = new CQueue<int>();
while (n--)
{
string command;
cin >> command;
if (command == "PUSH")
{
int value;
cin >> value;
cQueue->appendTail(value);
}
if (command == "POP")
{
cQueue->deleteHead();
}
}
}
return 0;
}
错误为:
1>1512.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall CQueue<int>::CQueue<int>(void)" (??0?$CQueue@H@@QAE@XZ),该符号在函数 _main 中被引用
1>D:\Visual Studio 2008\Projects\1512\Debug\1512.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>生成日志保存在“file://d:\Visual Studio 2008\Projects\1512\1512\Debug\BuildLog.htm”
1>1512 - 2 个错误,0 个警告
这是什么情况啊,求解答,雪地里跪等
------解决方案--------------------
#include <iostream>
#include <stack>
#include <string>
using namespace std;
template <typename T>
class CQueue
{
public:
CQueue(void);
~CQueue(void);
void appendTail(const T& node);
void deleteHead();
private:
stack<T> stack1;
stack<T> stack2;
};
template <typename T>
CQueue<T>::CQueue(void)
{
}
template <typename T>
CQueue<T>::~CQueue(void)
{
}
template <typename T>
void CQueue<T>::appendTail(const T& node)
{
stack1.push(node);
}
template <typename T>
void CQueue<T>::deleteHead()
{
if (stack2.size() <= 0)
{
while (stack1.size() > 0 )
{
T& data = stack1.top();
stack1.pop();
stack2.push(data);
}
if (stack2.size() == 0)
{
cout << "-1" << endl;
}
else
{
T head = stack2.top();
cout << head << endl;
stack2.pop();
delete &head;
}
}
}
int main(void)
{
int n = 0;
while (cin >> n)
{
CQueue<int>* cQueue = new CQueue<int>();
/*while (n--)
{
string command;
cin >> command;
if (command == "PUSH")
{
int value;
cin >> value;
cQueue->appendTail(value);
}
if (command == "POP")
{
cQueue->deleteHead();
}
}*/
}
return 0;
}
构造函数和析构函数没有实现