Inheritence and function overloading

A

ambarish.mitra

Class A has a public method f, and another class B is publicly derived
from A. The derived class B has also the same function but with
different arguments.

Question: In the scope of class B, is the function f overloaded? (yes/
no)


class A
{
public: int f(int x);
}

class B: public A
{
public: int f(int x, float y);
}
 
K

Kira Yamato

Class A has a public method f, and another class B is publicly derived
from A. The derived class B has also the same function but with
different arguments.

Question: In the scope of class B, is the function f overloaded? (yes/
no)


class A
{
public: int f(int x);
}

class B: public A
{
public: int f(int x, float y);
}

To see if it is overloaded or not, why not try to write some code to test it?

More specifically, try invoking f(1) and f(1,1.) on an B object.
 
L

ltcmelo

Class A has a public method f, and another class B is publicly derived
from A. The derived class B has also the same function but with
different arguments.

Question: In the scope of class B, is the function f overloaded? (yes/
no)

class A
{
public:    int f(int x);

}

class B: public A
{
public:  int f(int x, float y);



}- Hide quoted text -

- Show quoted text -

Hi.

In this case it's not an overload because the implementation in B
hides the implementation in A. Basically, C++ lookup rules will try to
find the symbol in class B. Since it'll find it, class A won't be
looked up.


Leandro Melo
 

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,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top