overloading base class functions

R

Rahul

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?
 
A

Abhishek Padmanabh

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

Pete Becker

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top