Code:compile is OK,but something wrong with link,I don't know what the matter. Help! The code as follows: //stack.h #include<iostream.h> template<class TYPE> class stack {public: stack(int s=10); ~stack() {delete [] stackptr; } int push(const TYPE&); int pop(TYPE&); int isFull() const {return top==size-1; } int isEmpty() const {return top==-1; } private: int size; int top; TYPE* stackptr; }; //stack.cpp #include<iostream.h> #include"stack.h" template<class TYPE> stack<TYPE>::stack(int s) {size=s>0&&s<1000?s:10; top=-1; stackptr=new TYPE[size]; } template<class TYPE> int stack<TYPE>::push(const TYPE& item) {if(!isFull()) {stackptr[++top]=item; return 1; } return 0; } template<class TYPE> int stack<TYPE>::pop(TYPE& popvalue) {if(!isEmpty()) {popvalue=stackptr[top--]; return 1; } return 0; } //main.cpp #include<iostream.h> #include"stack.h" int main() {stack<char> charstack; char c='a'; cout<<"pushing elements onto charstack"<<endl; while(charstack.push(c)) {cout<<c<<" "; c+=1; } cout<<endl<<"stack is full.cannot push"<<c<<endl<<"poping elements from charstack"<<endl; while(charstack.pop(c)) cout<<c<<" "; cout<<endl<<"stack is empty.cannot pop"<<endl; stack<float> floatstack(5); float f=1.1f; cout<<"pushing elements onto floatstack"<<endl; while(floatstack.push(f)) {cout<<f<<" "; f+=1.1f; } cout<<endl<<"stack is full.cannot push"<<f<<endl<<"poping elements from floatstack"<<endl; while(floatstack.pop(f)) cout<<f<<" "; cout<<endl<<"stack is empty.cannot pop"<<endl; stack<int> intstack; int i=1; cout<<"pushing elements onto intstack"<<endl; while(intstack.push(i)) {cout<<i<<" "; i+=1; } cout<<endl<<"stack is full.cannot push"<<i<<endl<<"poping elements from intstack"<<endl; while(intstack.pop(i)) cout<<i<<" "; cout<<endl<<"stack is empty.cannot pop"<<endl; return 0; } -------------------Configuration: aaa - Win32 Debug-------------------- Compiling... stack.cpp main.cpp Linking... main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<int>::pop(int &)" (?pop@?$stack@H@@QAEHAAH@Z) main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<int>::push(int const &)" (?push@?$stack@H@@QAEHABH@Z) main.obj : error LNK2001: unresolved external symbol "public: __thiscall stack<int>::stack<int>(int)" (??0?$stack@H@@QAE@H@Z) main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<float>::pop(float &)" (?pop@?$stack@M@@QAEHAAM@Z) main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<float>::push(float const &)" (?push@?$stack@M@@QAEHABM@Z) main.obj : error LNK2001: unresolved external symbol "public: __thiscall stack<float>::stack<float>(int)" (??0?$stack@M@@QAE@H@Z) main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<char>::pop(char &)" (?pop@?$stack@D@@QAEHAAD@Z) main.obj : error LNK2001: unresolved external symbol "public: int __thiscall stack<char>::push(char const &)" (?push@?$stack@D@@QAEHABD@Z) main.obj : error LNK2001: unresolved external symbol "public: __thiscall stack<char>::stack<char>(int)" (??0?$stack@D@@QAE@H@Z) Debug/aaa.exe : fatal error LNK1120: 9 unresolved externals 执行 link.exe 时出错. aaa.exe - 1 error(s), 0 warning(s)