undefined reference to 错误
我在Linux 下用g++编译c++程序时,链接阶段出现如下错误:
undefined reference to `CStack<int>::empty()'
collect2: ld returned 1 exit status
make: *** [testApp] Error 1
郁闷了好几天了,还是搞不定,
请求各位大虾帮忙
下面是测试代码:
#include "Stack.h"
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 CStack<int> myStack;
8
9 if(myStack.empty())
10 cout<<"myStack is empty"<<endl;
11
12 }
类Stack定义如下:
#ifndef __STACK_H__
2 #define __STACK_H__
3
4 #include <vector>
5 #include <iostream>
6
7 using namespace std;
8
9 template<class T> class CStack
10 {
11 public:
12 //CStack();
13
14 void push(T& item);
15 T& pop();
16 void print();
17 bool empty();
18 private:
19 vector<T> m_data;
20 };
21
22 #endif