POV-Ray : Newsgroups : povray.programming : C++ inheritance puzzler : Re: C++ inheritance puzzler Server Time
25 Apr 2024 12:59:30 EDT (-0400)
  Re: C++ inheritance puzzler  
From: Le Forgeron
Date: 27 Nov 2010 15:01:20
Message: <4cf16390@news.povray.org>
Le 27/11/2010 15:00, clipka nous fit lire :
> Hacking happily along at the POV-Ray code, I stumbled across this MS
> Visual Studio 2005 C++ anomaly:
> 
>   class A
>   {
>       protected:
>           void a() {}
>   };
> 
>   class B : public A
>   {
>       protected:
>           void b(A* other)
>           {
>               this->a();  // (1)
>               other->a(); // (2)
>           }
>   };
> 
> While (1) compiles fine, (2) raises an error C2248, "'A::a' : cannot
> access protected member declared in class 'A'"
> 
> What the F*** am I doing wrong here?

Issue of C++, or on the chair ?

(1) is ok because B is an A, so can access the protected function.
(2) is not allowed because a() of A is protected, so can only be called
by the object itself (in a gross simplification).

Works as designed.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.