gcc returns error with nested class

Posted by Nate on Stack Overflow See other posts from Stack Overflow or by Nate
Published on 2010-03-28T11:35:52Z Indexed on 2010/03/28 11:43 UTC
Read the original article Hit count: 415

Filed under:
|
|
|

Howdy,

I am attempting to use the fully qualified name of my nested class as below, but the compiler is balking!

template <class T> class Apple {
    //constructors, members, whatevers, etc...
public:
    class Banana {
    public:
        Banana() {
            //etc...
        }
        //other constructors, members, etc...
    };
};

template <class K> class Carrot{
public:
    //etc...
    void problemFunction()
    {
        Apple<int>::Banana freshBanana = someVar.returnsABanana(); //line 85
        giveMonkey(freshBanana);  //line 86
    }
};

My issue is, the compiler says:

Carrot.h:85: error: expected ';' before 'freshBanana'
Carrot.h:86: error: 'freshBanana' was not declared in this scope

I had thought that using the fully qualified name permitted me to access this nested class? It's probably going to smack me in the face, but what on earth am I not seeing here??

© Stack Overflow or respective owner

Related posts about c++

Related posts about nested-class