It's perfectly OK to create an object of the same type inside a class. You should be able to get it to work with stack<T>
, like this
template <class T>
class stack
{
...
void sort()
{
stack<T> st;
st.push(4);
}
...
};
It seems that stack st;
is correct according to the latest C++ standards, but maybe your compiler hasn't implemented this part of the C++ standard yet.
Having said that, it's not clear from your posted code why this is a template. If it were a template I'd expect to see
void push(const T& x)
{
...
}
T pop()
{
...
}
etc. Are you sure you want this to be a template? You should do that properly or not at all.