Hello,
how can I overload << with templates, please?
template <class T = int, size_t N = 100>
class Stack {
T _data[N];
size_t _index;
public:
Stack() : _index(0) { }
void push(const T& value) {
if ( _index != N) _data[_index] = value;
else printf("stack full\n");
}
friend std::ostream& operator<<(std::ostream& os, const Stack<T>& stack) {
for (int i=0; i < N; ++i)
os << _data[i] << " ";
return os;
}
};
template <class T = int, size_t N = 100>
class Stack {
T _data[N];
size_t _index;
public:
Stack() : _index(0) { }
void push(const T& value) {
if ( _index != N) _data[_index] = value;
else printf("stack full\n");
}
friend std::ostream& operator<<(std::ostream& os, const Stack<T>& stack) {
for (int i=0; i < N; ++i)
os << _data[i] << " ";
return os;
}
};
To copy to clipboard, switch view to plain text mode
error C2597: illegal reference to non-static member 'Stack<>::_data'
.....and others.....
error C2597: illegal reference to non-static member 'Stack<>::_data'
.....and others.....
To copy to clipboard, switch view to plain text mode
Bookmarks