3

I have the following:

using namespace std;

template<class T> class olsm;                 
template<class T> istream& operator>>(istream& in, olsm<T>& x);
template<class T> ostream& operator<<(ostream& out, olsm<T>& x);

template <class T>                                              
class olsm {

    friend istream& operator>> <> (istream& in, olsm& x);
    friend ostream& operator<< <> (ostream& out, olsm& x);

    public:                                
        class node {                           
            public:
        };

        ///Other stuff
};      

////More stuff

template<class T>
ostream& operator<<(ostream& out, olsm<T>& x) {

    olsm<T>::node* rowNode = x;

    //Even more stuff!

    return out;
}

But when I try to compile I get,

error: 'rowNode' was not declared in this scope

which is odd because I get the error on the line I'm trying to declare it at. Does anyone know why?

iammilind
  • 68,093
  • 33
  • 169
  • 336
Mediocre Gopher
  • 2,274
  • 1
  • 22
  • 39
  • 1
    I don't think this line will work - think about what you are doing, assigning an object to a pointer. – Nim Oct 20 '11 at 07:50

2 Answers2

9

olsm<T>::node* is a dependent name (it depends on a template parameter). You need to write typename olsm<T>::node* to tell the compiler that it refers to a type (by default, the compiler will assume it refers to a member).

See this question for a more detailed explanation.

Community
  • 1
  • 1
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
3

This line:

olsm<T>::node* rowNode

should be:

   typename olsm<T>::node* rowNode
// ^^^^^^^^  You need to specify the member is a typename.
Martin York
  • 257,169
  • 86
  • 333
  • 562