rajsekhar
rajsekhar

Reputation: 551

Modify base class so the changes get reflected in derived class

Suppose I have a base class Polygon.I have derived classes from it like Rectangle and many more.Now if I need to add a new function to class Polygon and I dont have access to source code of base class Polygon or derived classes.How can I do it? Is it possible?

Upvotes: 0

Views: 98

Answers (2)

Alican
Alican

Reputation: 286

using an intermediary class that inherits the base class can solve the problem. rectangle and the others inherits it so that if it is required to add new methods, it is implemented inside the intermediary class.

Upvotes: 1

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385174

No.

If you don't have access to source code, then you can't modify source code.

You may only add member functions in the class's original definition.

Upvotes: 0

Related Questions