c++ and inheritance
- From: "Tyler Littlefield" <tyler@xxxxxxxxxxxxx>
- To: <programmingblind@xxxxxxxxxxxxx>
- Date: Fri, 26 Dec 2008 12:24:38 -0800
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: