Hello all.
I am really at my wits end here. I cannot instantiate an instance of a templated class. ( I have looked through the archives and can't find an answer!)
My templated class is called Jstack. It is only part comleted but enough to test:
template< class STACKTYPE> class Jstack
{
public:
Jstack(void);
~Jstack() {void};
void push(STACKTYPE objIn);
STACKTYPE pop ();
private:
STACKTYPE * stackPtr;
int top;
};
template<class STACKTYPE>
Jstack<STACKTYPE>::Jstack(){
stackPtr = new STACKTYPE[10];
top = 0;
}
template<class STACKTYPE>
void Jstack<STACKTYPE>:ush(STACKTYPE pushVal){
if(top < 11)
{
stackPtr[top++] = pushVal;
}
else
{
//make a bigger array
}
}
template<class STACKTYPE>
STACKTYPE Jstack<STACKTYPE>:op()
{
return stackPtr[top--];
}
//*********************************************
Now I test it with this little program:
#include <iostream.h>
#include "Jstack.h"
int main ()
{
Jstack < int > myStack();
myStack.push(3);
return 0;
}
//*************************************
Ok the problem is when I type "myStack." I expect the little pop up menu to come up which offers the choice of member functions. Unfortunatley, it doesnt and sure enough when I compile I get:
error C2228: left of '.push' must have class/struct/union type
In other words, my instance of Jstack has not been instantiated properly. Can anyone tell me why this is? It's driving me nuts.
thanks,
john
I am really at my wits end here. I cannot instantiate an instance of a templated class. ( I have looked through the archives and can't find an answer!)
My templated class is called Jstack. It is only part comleted but enough to test:
template< class STACKTYPE> class Jstack
{
public:
Jstack(void);
~Jstack() {void};
void push(STACKTYPE objIn);
STACKTYPE pop ();
private:
STACKTYPE * stackPtr;
int top;
};
template<class STACKTYPE>
Jstack<STACKTYPE>::Jstack(){
stackPtr = new STACKTYPE[10];
top = 0;
}
template<class STACKTYPE>
void Jstack<STACKTYPE>:ush(STACKTYPE pushVal){
if(top < 11)
{
stackPtr[top++] = pushVal;
}
else
{
//make a bigger array
}
}
template<class STACKTYPE>
STACKTYPE Jstack<STACKTYPE>:op()
{
return stackPtr[top--];
}
//*********************************************
Now I test it with this little program:
#include <iostream.h>
#include "Jstack.h"
int main ()
{
Jstack < int > myStack();
myStack.push(3);
return 0;
}
//*************************************
Ok the problem is when I type "myStack." I expect the little pop up menu to come up which offers the choice of member functions. Unfortunatley, it doesnt and sure enough when I compile I get:
error C2228: left of '.push' must have class/struct/union type
In other words, my instance of Jstack has not been instantiated properly. Can anyone tell me why this is? It's driving me nuts.
thanks,
john