P
Puvendran
Hi,
I am writing a simple program to use templates. Basically the program
should be able create a stack of any type with ultimately 2 methods
one to add (push) and one to remove (pop) from the stack.
I am getting a compilation error thus - it's the stack<int>
s(10)declaration which seems to be the problem
Undefined first referenced
symbol in file
stack<int>::stack(int) /var/tmp/ccdiGgf1.o
ld: fatal: Symbol referencing errors. No output written to p
collect2: ld returned 1 exit status
Programs involved :
The main prog is
#include "p_stack.h"
//#include <iostream.h>
void
main()
{
stack<int> s(10);
int i;
for (int j=0;j < 12; j++)
{
//s.push(j);
}
for (int j=0;j < 10; j++)
{
//cout << s.pop() << endl;
}
}
The "p_stack.h" is
#include <vector>
template<class T>
class stack
{
public :
//int max_size;
//int curr_size;
vector<T> v;
stack(int);
//void push(T);
//T pop();
};
p_stack.cc is
#include "p_stack.h"
#include <string>
template<class T>
stack<T>::stack(int i)
{
v.resize(i);
}
I thank you in advance for any assistance.
Puvendran
I am writing a simple program to use templates. Basically the program
should be able create a stack of any type with ultimately 2 methods
one to add (push) and one to remove (pop) from the stack.
I am getting a compilation error thus - it's the stack<int>
s(10)declaration which seems to be the problem
Undefined first referenced
symbol in file
stack<int>::stack(int) /var/tmp/ccdiGgf1.o
ld: fatal: Symbol referencing errors. No output written to p
collect2: ld returned 1 exit status
Programs involved :
The main prog is
#include "p_stack.h"
//#include <iostream.h>
void
main()
{
stack<int> s(10);
int i;
for (int j=0;j < 12; j++)
{
//s.push(j);
}
for (int j=0;j < 10; j++)
{
//cout << s.pop() << endl;
}
}
The "p_stack.h" is
#include <vector>
template<class T>
class stack
{
public :
//int max_size;
//int curr_size;
vector<T> v;
stack(int);
//void push(T);
//T pop();
};
p_stack.cc is
#include "p_stack.h"
#include <string>
template<class T>
stack<T>::stack(int i)
{
v.resize(i);
}
I thank you in advance for any assistance.
Puvendran