a class inside a class

Started by
12 comments, last by alnite 21 years, 2 months ago
quote:Original post by SabreMan
Edit: hold on, you didn''t mean that, did you? You can do this:
Oops, looks like my fingers and my mind spoke different language. This was what I mean: Does B exist in C when C inherit A considering B is protected/public? If so, can I overload B within the namespace of C without declaring a new class (class D, in dalleboy''s example).

  class A{public:    class B    {        int foo;    };};class C : public A{    class B   // overloaded B    {        int newfoo;    };};  


return 0;
Advertisement
Tazel - Theoretically both are possible. In practice, some compilers (e.g. Visual Studio) have trouble with templated classes which have non-inline members (including member classes).

alnite - You''re not overriding (nor even overloading), you''re hiding, just as you would a static member function.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
As to where or why you use this particular technique; it''s used all over the STL(e.g.list::iterator)

Peace Out!
quote:Original post by SecondBest
As to where or why you use this particular technique; it''s used all over the STL(e.g.list::iterator)

No it isn''t. The technique you are talking about is to code a typedef within the list class, but the iterator class will be defined elsewhere.

This topic is closed to new replies.

Advertisement