overloading base class functions



 DEVELOP > c-Plus-Plus > overloading base class functions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Rahul"
Date: 18 Dec 2007 12:03:17 PM
Object: 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?
.

User: "Pete Becker"

Title: Re: overloading base class functions 18 Dec 2007 12:49:02 PM
On 2007-12-18 13:03:17 -0500, Rahul <sam_cit@yahoo.co.in> 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)
.

User: "Abhishek Padmanabh"

Title: Re: overloading base class functions 18 Dec 2007 12:20:31 PM
On Dec 18, 11:03 pm, Rahul <sam_...@yahoo.co.in> 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!)
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER