answersLogoWhite

0


Best Answer

In order for a base class to protect derived classes, so that changes to the base class do not affect the derived classes, you must make sure that the public interface exposed by the base class does not change when the implementation of those public methods do change. You can also prevent inadvertant access to the base class attributes from the derived class, by making them private.

class base {

public:

base(...) {...}; /* constructor */

base~(...) {...}; /* destructor */

method(...) {...}; /* other public methods */

private:

... etc.

}

class child : base {

public:

...

private:

...

}

So long as the calling sequence and functionality (interface) of the base class public methods do not change, the implementation of those public methods can change, and the private methods and attributes can change, without impacting any child class.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can a base class protect derived classes so that changes to the base class will not affect them explain with example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions