Click here to Skip to main content
15,915,093 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Inheritance. Pin
WREY18-Dec-02 10:56
WREY18-Dec-02 10:56 
GeneralRe: Inheritance. Pin
Alvaro Mendez18-Dec-02 12:41
Alvaro Mendez18-Dec-02 12:41 
GeneralRe: Inheritance. Pin
WREY19-Dec-02 7:18
WREY19-Dec-02 7:18 
GeneralRe: Inheritance. Pin
Alvaro Mendez20-Dec-02 6:05
Alvaro Mendez20-Dec-02 6:05 
GeneralRe: Inheritance. Pin
WREY20-Dec-02 7:18
WREY20-Dec-02 7:18 
GeneralRe: Inheritance. Pin
Chris Richardson19-Dec-02 18:59
Chris Richardson19-Dec-02 18:59 
GeneralRe: Inheritance. Pin
WREY19-Dec-02 21:49
WREY19-Dec-02 21:49 
GeneralRe: Inheritance. Pin
Chris Richardson20-Dec-02 7:03
Chris Richardson20-Dec-02 7:03 
The first example illustrates why you can't access the protected base member. The second example was only illustrating the way to avoid ambiguities you had discussed with Alvaro Mendez. Let me see if I can show a better example of why the compiler is complaining.

class Base
{
protected:
   int x;
};

class Derived : public Base
{
public:
   void Function()
   {
      Base * pBase = new Base;
      pBase->x = 10; // <<A>> Obviously incorrect.
      delete pBase;

      // Just because we use the "this" pointer in the next line of code, doesn't mean we should be able to access the base member.
      // We have taken away our access to the Base protected member, because we have told the compiler that we are now working with
      // a "Base" pointer, instead of a "Derived" pointer.
      // The only "Base" members we have access to, are from the "this" pointer, and once we cast that to a different type of object,
      // in this case "Base", we lose access to those members.
      pBase = (Base*)this;
      pBase->x = 10; // Just as incorrect as the line marked <<A>>
   }
};


Chris Richardson

Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
GeneralRe: Inheritance. Pin
WREY20-Dec-02 7:24
WREY20-Dec-02 7:24 
QuestionHow to delete an HBITMAP? Pin
Joan M18-Dec-02 9:37
professionalJoan M18-Dec-02 9:37 
AnswerRe: How to delete an HBITMAP? Pin
Christian Graus18-Dec-02 9:49
protectorChristian Graus18-Dec-02 9:49 
GeneralRe: How to delete an HBITMAP? Pin
Joan M18-Dec-02 9:59
professionalJoan M18-Dec-02 9:59 
AnswerRe: How to delete an HBITMAP? Pin
Paul M Watt18-Dec-02 9:51
mentorPaul M Watt18-Dec-02 9:51 
GeneralRe: How to delete an HBITMAP? Pin
Joan M18-Dec-02 9:59
professionalJoan M18-Dec-02 9:59 
GeneralWeird Case Pin
Sidney18-Dec-02 9:34
Sidney18-Dec-02 9:34 
GeneralRe: Weird Case Pin
Chris Richardson18-Dec-02 10:31
Chris Richardson18-Dec-02 10:31 
GeneralRe: Weird Case Pin
Sidney18-Dec-02 10:57
Sidney18-Dec-02 10:57 
GeneralRe: Weird Case Pin
Chris Richardson19-Dec-02 20:32
Chris Richardson19-Dec-02 20:32 
GeneralMFC Grid - How To Tab Out of... Pin
RFID Chris18-Dec-02 9:14
RFID Chris18-Dec-02 9:14 
GeneralReverse link list test Pin
Todd Smith18-Dec-02 8:49
Todd Smith18-Dec-02 8:49 
GeneralRe: Reverse link list test Pin
Tim Smith18-Dec-02 9:12
Tim Smith18-Dec-02 9:12 
QuestionDlls dialogs in FormViews? Pin
Ricky_TheBard18-Dec-02 8:27
Ricky_TheBard18-Dec-02 8:27 
QuestionFunctions to manage user profiles in a server ? Pin
Cris18-Dec-02 8:22
Cris18-Dec-02 8:22 
QuestionFlexible deriving a CAsyncSocket class? Pin
User 665818-Dec-02 7:56
User 665818-Dec-02 7:56 
Generalxlocale & xlocnum produce warnings at level 4 Pin
scott sanders18-Dec-02 6:01
scott sanders18-Dec-02 6:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.