Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloading base class functions

Reply
Thread Tools

overloading base class functions

 
 
Rahul
Guest
Posts: n/a
 
      12-18-2007
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?
 
Reply With Quote
 
 
 
 
Abhishek Padmanabh
Guest
Posts: n/a
 
      12-18-2007
On Dec 18, 11:03 pm, Rahul <(E-Mail Removed)> wrote:
> 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!)
 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      12-18-2007
On 2007-12-18 13:03:17 -0500, Rahul <(E-Mail Removed)> said:

> 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)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base class method Need base class value Karan Rajput Ruby 2 12-22-2010 04:47 PM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
base class public type (non template and template base class) Hicham Mouline C++ 1 04-20-2009 03:28 PM
Access of base class' private base class: qualification required, why Alf P. Steinbach C++ 6 09-03-2005 04:03 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments