0
我正在做一個程序,我需要將對象存儲在堆棧中。我定義堆棧作爲模板類是這樣的:使用堆棧來存儲對象
template < class T >
class stackType
{
private:
int maxStackSize;
int stackTop;
T *list; // pointer to the array that holds the stack elements
public:
stackType(int stackSize); // constructor
~stackType(); // destructor
void initializeStack();
bool isEmptyStack();
bool isFullStack();
void push(T newItem);
T top();
void pop();
};
這是我的課:
class Matrix_AR
{
public:
float **Matrix; // Matrix as a pointer to pointer
int rows, columns; // number of rows and columns of the matrix
// class function
Matrix_AR();
Matrix_AR(int m, int n); // initialize the matrix of size m x n
void inputData(string fileName); // read data from text file
void display(); // print matrix
};
然而,當我宣佈這樣
void myfunction(stackType<Matrix_AR>& stack)
{
Matrix_AR item1, item2, item3;
stack.push(item1);
stack.push(item2);
stack.push(item3);
}
我一直得到一個功能錯誤。我試圖修復它五個小時,仍然無法弄清楚。任何人都可以幫忙,請!!!
Undefined symbols for architecture x86_64:
"Matrix_AR::Matrix_AR()", referenced from:
myfunction(stackType<Matrix_AR>&, char&, bool&)in main.o
ld: symbol(s) not found for architecture x86_64
沒有使用[std :: stack](http://en.cppreference.com/w/cpp/container/stack)的任何特定原因? – Collin