473,698 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

overloading base class functions

Hi Everyone,

I read in an article that over loading a base class function
(ordinary, non-static non-virtual member function) hides the base
class versions in the derived class.

However, as in the following code, i'm able to access the base class
member functions,

class A
{
public: void sample()
{
printf("A\n");
}
};

class B : public A
{
public: void sample(int)
{
//A::sample();
printf("B\n");
}
};

int main()
{
B obj;
obj.sample(5);
obj.A::sample() ; // Able to access base class versions...
return(0);
}

What is correct significance for overloading?
Dec 18 '07 #1
2 1510
On Dec 18, 11:03 pm, Rahul <sam_...@yahoo. co.inwrote:
Hi Everyone,

I read in an article that over loading a base class function
(ordinary, non-static non-virtual member function) hides the base
class versions in the derived class.

However, as in the following code, i'm able to access the base class
member functions,

class A
{
public: void sample()
{
printf("A\n");
}

};

class B : public A
{
public: void sample(int)
{
//A::sample();
printf("B\n");
}

};

int main()
{
B obj;
obj.sample(5);
obj.A::sample() ; // Able to access base class versions...
Yes, you can invoke the base member that way. But hiding is referred
to as in you cannot get this to compile:

obj.sample();

(you can use using declaration in derived class to get this to work
even)

What is correct significance for overloading?
It is not called overloading. Overloading happens in same scope. This
is re-defining (which causes hiding - I rhymed... yea!)
Dec 18 '07 #2
On 2007-12-18 13:03:17 -0500, Rahul <sa*****@yahoo. co.insaid:
I read in an article that over loading a base class function
(ordinary, non-static non-virtual member function) hides the base
class versions in the derived class.

However, as in the following code, i'm able to access the base class
member functions,
That's because "hides" has no technical meaning, so you're left to
guess at what it was intended to mean. The actual rule is that
overloading occurs among signatures with the same name, defined in the
same scope. When you define a name in a derived class, any members of
the base class with the same name do not take part in overloading in
the derived class. You can still see them, as your example shows, so
they're not hiding. They're just not part of the derived class's
overload set.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Dec 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
4717
by: Terje Slettebø | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP manual mentions "overloading" (http://no.php.net/manual/en/language.oop5.overloading.php), but it isn't really overloading at all... Not in the sense it's used in other languages supporting overloading (such as C++ and Java). As one of the...
7
373
by: Katie | last post by:
my one base class is a linklist class.now i'd like to inherit it by another class.The problem is that when i use the derived class i can't access the base class's pointers.classic type mismatch.how do i link the derived class if i can't compare the derived class's pointers to the linklist class's pointers? do i do it with overloading?i tried that,but could get it to work.my handbooks (all 4 of them) has no example on how to do...
1
2368
by: Xiangliang Meng | last post by:
Hi, all. When reading C++ books, I'm alway confused by those terms "redefining functions", "overloading functions" and "overriding functions". Please give me some comments on those terms. Thanks. If giving more strategy hehind them, more helpful. Best Regards,
7
1364
by: deancoo | last post by:
I'm having some trouble with a couple of classes I've created (base and derived). I had defined a function in a derived class, and then overloaded that function name in a class derived from the first derived class. Now I need to store objects instantiated from these classes (excluding the base class) in a container. The container is defined to hold objects of the base class type. So far so good, however, when it comes time to use the...
15
24003
by: Susan Baker | last post by:
Hello everybody, I'm new to C++ (I have some C background). I've read up on this topic a few times but it just dosen't seem to be sinking in. 1. Whats the difference between overloading and overriding? 2. When is one preferable to use as opposed to the other? 3. How are virtual functions related to this topic (overloading/overriding) - a real world example of using virtual functions would be very much appreciated.
1
6648
by: ravinderthakur | last post by:
hi all experts, i was just thinking about making overloaded operators virtual. i was wordering what could be the implications of such scenarios. i will be thankful if somebody can provide point out some general issues in making overloaded virtual or point me to some resource having explaination about the same.
5
1983
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary, not to get polymorphic behavior. None of them has virtual methods, and are self contained (no destructor at all) thus do not have a chance to have memory error. Thus the derived classes has additional functionality, not additional data.
3
2031
by: Chameleon | last post by:
What is better if you want upcasting in intermediate classes like below? Multiple Inheritance and Overloading or simply RTTI? RTTI wants time but MI and Overloading create big objects (because of virtual) and finally they need time too to access objects inside big object. (Examples looks complicated but are very simple) Paradigm #1: MI & Overloading =============================
8
3219
by: yashwant pinge | last post by:
#include<iostream> using namespace std; class base { public: void display() { } };
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.