Re: c++ and inheritance

will do, thanks.

  ----- Original Message ----- 
  From: Ken Perry 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Friday, December 26, 2008 8:27 PM
  Subject: RE: c++ and inheritance


   

  The keyword I think you're looking for is protected.  It should do what you 
want.  If not what you would have to do is rap your message calls in functions 
thus keeping it private and allowing public functions to access it correctly.  
I think though Protected does what you want you use it like public and private. 
 Just go read the docs on that and I think your all set.

   

  Ken

   

  From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Tyler Littlefield
  Sent: Friday, December 26, 2008 3:25 PM
  To: programmingblind@xxxxxxxxxxxxx
  Subject: c++ and inheritance

   

  Hello list,

  I'm writing a basic framework for some of my applications to use, to keep me 
from reinventing the wheel every time I start something new

  I'm working on a basic Exception class, which I can use coupled with others 
to throw exceptions when needed.

  now, here's my problem.

  My exception looks somewhat like this:

  class Exception

  {

  public:

  virtual Exception(char* err);

  virtual exception();

  ~exception();

  virtual void SetMessage(char* err);

  virtual char* GetMessage();

  private:

  char* Message;

  };

  this works, but when I have other exceptions inheriting this, I have to 
inherit both public and private scope.

  Is there a more efficient way of doing this?

  I can do something like:

  class MemoryException:public Exception

  {

  ...

  private:

  char* Message

  };

  but that requires that message is defined in every new exception class.

  I would like message to remain private so that it does not get changed by 
calls, and so that if needed SetMessage can be overridden to just return 
without changing the message.

  TIA,

   

Other related posts: