473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Hiding an inherited public function

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
0 951

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

Similar topics

6
by: thechaosengine | last post by:
Hi all, Is there a way to hide a member in a subclass that has been inherited from a base class? Lets leave aside any issues regarding whether its a good idea for a moment. Here's an example...
7
by: Tron Thomas | last post by:
Under the right compiler the following code: class Base { public: virtual void Method(int){} }; class Derived: public Base {
4
by: Dan | last post by:
I have a need to make a set of classes that all share the same public methods, some implementation and some data. So, I made an abstract base (BaseClass) with an interface (IBaseClass) and a...
4
by: Fabio Cannizzo | last post by:
Is there a way to hide an inherited protected member so that it is no longer accessible nor visible from the inherited classes? The code below makes c1.foo() no longer accessible, but c2.foo is...
7
by: Dennis | last post by:
I have a class named myclass that inheirits from "baseclass". There is a property of "baseclass" that I don't want exposed in the IDE. The MSDN documentation says" "A derived type can hide an...
9
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function...
6
by: Ryan H. | last post by:
A very simple example of something that acts quite odd: class TopClass { public: TopClass(){ } virtual ~TopClass(){ } virtual int myFunc() = 0; };
9
by: Torben Laursen | last post by:
Hi I have a class that I use in Excel to define some custom functions. The problem that I have is that the class also has some building functions that for some reason is there: ToString...
7
by: Mike | last post by:
According to the MSDN (see reference below), it is possible to change a base class function from public to private. How is this done? I've tried using "new", but the function is still accessible. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.