'undefined reference' problem

Hi,

I got the 'undefined reference' problem. So I can't compile my code. Here is my code

Stack.cpp
[#include "Stack.h"

using namespace std;

template<class T>
void Stack<T>::polishExp(char array[]){
for(int i = 0; i < 5; i++){
cout << array[i];
return array[i];
}
}

template<class T>
void Stack<T>::reverseArr(char array[]){
int last = 4;
int first = 0;
char tmp;

while(first < last){
tmp = array[first];
array[first] = array[last];
array[last] = tmp;
first++;
last--;
}
}

template<class T>
bool Stack<T>::isNum(char &n){
if(isdigit(n)){
return false;
}else{
return true;
}
}

template<class T>
void Stack<T>::push(const T& obj) {
Node* tmp = new Node;
tmp->data = obj;
tmp->link = top;
top = tmp;
}

template<class T>
T Stack<T>::pop(){
if (empty())
throw runtime_error("Stack empty, cannot pop");
Node* tmp = top;
top = top->link;
T data = tmp->data;
delete tmp;
return data;
}

template<class T>
bool Stack<T>::empty(){
return top == 0;
}

template<class T>
Stack<T>::~Stack(){
while (!empty()) pop();
} ]

and this is my main file

[#include <iostream>
#include <fstream>
#include <stack>
#include <stdexcept>
#include "Stack.h"

using namespace std;

void polishExp(char expression[]);
void reverseArr(char arr []);
bool isNum(char &exp);

int main()
{
stack<int> s;
char expression[] = "/2*+435";

polishExp(expression);//display our rpn expression on the screen

cout<<endl;//newline space

int n;//a number ot push onto the stack
int result;//a result after performing
reverseArr(expression);

for(unsigned int i = 0; i < 7; i++){
if(isNum(expression[i])==true){
char c = expression[i];
n = c-'0';//parse the char to an integer
s.push(n);
}if(expression[i]=='+'){
int x = s.top();
s.pop();
int y = s.top();
s.pop();
result = x+y;
s.push(result);
}if(expression[i]=='-'){
int x = s.top();
s.pop();
int y = s.top();
s.pop();
result = y-x;
s.push(result);
}if(expression[i]=='*'){
int x = s.top();
s.pop();
int y = s.top();
s.pop();
result = x*y;
s.push(result);
}if(expression[i]=='/'){
int x = s.top();
s.pop();
int y = s.top();
s.pop();
result = y/x;
s.push(result);
}
}
cout<<"result of expression: "<<s.top();//result should be 17...

return 0;
}

][/code]]


So the error says that there are undefined reference to polishExp(char*), undefined reference to reverseArr(char*) and undefined reference to isNum(char&).

Feel free to help. Thank you in advance.
Last edited on
for class template compile the header and implementation in the same file and see if the problem persists:
http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
Topic archived. No new replies allowed.