Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)
my problem is this, i have a class (we shall name A) inheriting class B and my compiler will not let my A::[memberfunction] access the private variables in class B, which of course through inheritance are now variables in class A. this is driving me nuts, it can be ignored in this case because its in a dll, so i can make everything in B public and just not include the should be private ones in the including header file. but shouldnt a class that inherits something be able to access its own members? Edited by rifter1818
Posted

In order for a derived type to have access to it's base members, you have to put it in protected scope, private members can't be accessed.

class B
{
private:
   int privateInt;     // A cannot access
protected: 
   int protectedInt; // A can access
};

class A : public B
{
public:
   void SetNumber(int value) { protectedInt = value; }
   int GetNumber() { return protectedInt; }
};

"For every complex problem, there is a solution that is simple, neat, and wrong." - H. L. Mencken

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...