我正在 Ubuntu 11.04 上的 Netbeans 7.1 上开发 C++。我想知道是否有人可以告诉我为什么 Stack fs(5); 被视为对 `Stack::Stack(int)' 的未定义引用。为什么它不被视为一个带有用于 T 的浮点数的类?
#include <iostream>
using namespace std ;
template <class T>
class Stack
{
public:
Stack(int = 10) ;
~Stack() { delete [] stackPtr ; }
int method1(const T&);
int method2(T&) ;
int method3()const { return top == -1 ; }
int method4() const { return top == size - 1 ; }
private:
int attribute1 ;
int attribute2 ;
T* stackPtr ;
} ;
using namespace std;
int main()
{
// This line gives the error message "undefined reference to `Stack<float>::Stack(int)'"
Stack<float> fs(5);
return 0;
}
谢谢,彼得。