473,395 Members | 1,823 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,395 software developers and data experts.

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 1492
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
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...
7
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...
1
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....
7
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...
15
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...
1
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...
5
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,...
3
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...
8
by: yashwant pinge | last post by:
#include<iostream> using namespace std; class base { public: void display() { } };
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.