views:

72

answers:

4

hello, i got a compile error which i do not understand. i have a h/cpp file combination that does not contain a class but just defines some utility functions. when i try to use a struct that is defined in another class i get the error:

error C2027: use of undefined type 'B::C'

so, stripped down to the problem, the h-file looks like this

namespace A {
    void foo(B::C::SStruct const & Var);
}

the definition of SStruct is in a class which is in another h-file, that is of course included.

namespace B {
    class C {
        public:
        struct SStruct { };
    };
}

the strange thing is, i can use this struct in other classes fine, it just seems to be related to this one h-file which contains just utility functions. what am i missing here? thanks!

+5  A: 

After correcting missing semicolons etc. this compiles:

namespace B {
    class C {
        public:
        struct SStruct { };
    };
}
namespace A {
    void foo(B::C::SStruct const & Var);
}

Obviously, if the order of the two namespaces were switched, this would not work. Possibly you are #including your headers in the wrong order. If this is the error, that's bad design - you should not allow header order to matter in your code.

anon
thanks. sorry, i forgot to mention this in my original post, it is infact public.
clamp
yep, it seems it is the order. thanks! i will need to rethink the organization of my h-files.
clamp
A: 

I assume you meant "class C", not "Class C".

struct SStruct is private to class C (private being the default visibility of class members).

As such, it is not visible outside class C and its friends, which does not include A::foo().

DevSolar
thanks. sorry, i forgot to mention this in my original post, it is infact public.
clamp
A: 
Class C { 
        struct SStruct { }; 
    } 

==>

class C { 
public:
        struct SStruct { }; 
    };
Alexey Malistov
thanks. sorry, i forgot to mention this in my original post, it is infact public.
clamp
A: 

Your class is missing a semicolon after the definition. It should be:

namespace B {
    class C {
        public:
        struct SStruct { };
    }; // <=== Here
}
zipcodeman
yes thanks, but that was not the problem
clamp