template class input operator overloading
Feb 11, 2014 at 4:52am UTC
Basically I have a template class that I want to be able to store data using a function I named void Push(). I want to overload the input operator >> so that I can ask the user to enter in values and it will store them.
1 2 3 4 5
istream& operator >> (istream &in, STACK <T, n> &s)
{
in >> s.Push(x);
return in;
}
This doesn't work though. I am not sure why. Any help will be appreciated. Thanks.
Feb 11, 2014 at 5:48am UTC
what is x ?
1 2 3 4 5 6 7 8
template <class T, /* */ n>
istream& operator >> ( istream& in, STACK <T, n>& s )
{
T x
in >> x
s.Push( x );
return in;
}
Last edited on Feb 11, 2014 at 5:48am UTC
Feb 11, 2014 at 5:57am UTC
x is what the user will input, i will try this
Feb 11, 2014 at 5:50pm UTC
i try this, but when I put cin >> s (from MyClass <int, 4> s) it still says no operator matches those operands for the class
Feb 12, 2014 at 6:44am UTC
can you show the relevant code ?
Topic archived. No new replies allowed.