Topic: Ineritance inside Encapsulation


Author: Matthew Versluys <versluys@mediaone.net>
Date: 1998/09/30
Raw View
Just curious as to whether this code is legal ...

-------------------------------------------------------
#include "stdio.h"

class A
{
public:
 class C
 {
  public:
    void Func()
    {
      printf("C\n");
    }
 };
};

class B
{
public:
  class C : public A::C
  {
  public:
    void Func()
    {
      A::C::Func();
    }
  };
};

void main(void)
{
  B::C bc;

  bc.Func();
}
-------------------------------------------------------

This works fine under GNU++ but does not compile under Visual C/C++ 5 or 6
and reports the following error, which implies that it does not realize that
B::C was derived from A::C.

error C2352: 'A::C::Func' : illegal call of non-static member function

But the plot thickens since you can put protected members in A::C and access
them from B::C without problem.

If it turns out this is not legal then I'm content to find an alternate
solution to my problem, otherwise I'll take it to the friendly people at
Microsoft.

Cheers,
Matt.





[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]