By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,988 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,988 IT Pros & Developers. It's quick & easy.

Hiding an inherited public function

P: 1
Is it possible for an inheritor class to hide one of its parents' public functions?

I don't mean just replacing the functionality, but to make it such that "Child.X()" is not a valid call, even though "Parent.X()" would be.

An example may make this clearer.

I'm working on a program that calculates a flight path for a small aircraft. The base class is Flight, which has a starting point and an ending point, and has a function called FlightTime that calculates the, well, flight time along a great circle route from A to B.

Then there's a FlightRoute, which inherits Flight. A flight route is a more complicated thing -- it still has a start point and and end point and so on, all inherited from Flight, but a FlightRoute also takes into account the need for fuel stops along the way, and has functions and members to calculate and store a list of those fuel stops.

If I instantiate a FlightRoute object, I have two different sorts of flight time -- A DirectFlightTime function, which is the same as FlightTime, a "nonstop" A-to-B-at-speed-Y sort of thing, and RouteFlightTime, which sums up the flight time from A to stop1, stop1 to stop2, ... , and stopN to B.

So this is the problem: I want that inherited FlightTime function to go away because it has an ambiguous name from the point of view of a FlightRoute. I want to rename it "DirectFlightTime", or create a member function with that name which simply calls MyBase.FlightTime. I want FlightRoute.FlightTime to be an invalid, unknown function, even though Flight.FlightTime is a perfectly valid call.

Is that possible?
Dec 7 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.