I believe this is my ignorance in my coding, humph /:-(
or a fixme yet to be in gnu g++: Feb 26 1998 B19 Win32 on NT
Thanks in advance :-)
goal: use different files for template based classes, main, and headers.
trys: compile/run fine when implimentatons are in same file/scope of
instantiati
obstacle: either stack dump or undefined reference(s) from make.
question: work around? fix? corrections to code?
below is the coding for "goal".
trys coded with in same file/scope.
*.h =========================
const int defaultStack = 50;
template
class Stack
{ // vars
int top;
T *data;
public:
Stack(int size = defaultStack);
Stack(char*);
~Stack();
int getsize();
void push(T);
T pop();
};
*.cpp =======================
#include "stack.h"
const int defaultSize = 128;
template
Stack::Stack(int s)
{ // "vars" = 0;
data = new T(size);
}
template
Stack::Stack(char* s)
{ // "vars" = 0;
data = new T(size);
}
template
Stack::~Stack()
{ delete [] data;
}
template
void Stack::push(T d)
{ data[top++] = d;
}
template
int Stack::getsize()
{ return top;
}
template
T Stack::pop()
{ return data[--top];
}
main.cpp ====================
#include *.h // all...
int main( void )
{ int i;
Stack nInt(20);
nInt.push(5);
cout << "pushed 5" << endl;
for( int j=0;j<2;++j )
{ i = nInt.pop();
cout << "i is poped: " << i << endl;
}
Stack cpStack(20); // stack of strings
cpStack.push("first word");
cpStack.push("second word");
cpStack.push("number three word");
cout << endl << "here are " << cpStack.getsize() << " strings" << endl;
for( int j=0;j < cpStack.getsize()+2;++j )
cout << endl << cpStack.pop();
cout << endl << "stack size " << cpStack.getsize() << endl;
cout << endl << "end main";
return 0;
}
___
* OFFLINE 1.58
--- Maximus/2 2.02
---------------
* Origin: The HUB * Austin TX * Centex PCUG * 512-346-1852 (1:382/1201)
|