method inheritance with default parameter

Á

Á¤Á¤±Õ

hi, all

I have question in method inheritance.

in my opinion, first method call in main function report ambiguity. but
resolves dervied class's method.

thanks in advance.

#include <iostream>

using namespace std;

class Base
{
public:
int f(int b, int c=0)
{
cout<<"Base::f"<<endl;
}
};

class Derived:public Base
{
public:
int f(int a=0)
{
cout<<"Derived::f"<<endl;
}

};

int main()
{
Derived a;
a.f(0);
a.f(0,1); // c++ reports an error.
}
 
V

Victor Bazarov

Á¤Á¤±Õ said:
hi, all

I have question in method inheritance.

in my opinion, first method call in main function report ambiguity.
but resolves dervied class's method.

thanks in advance.

#include <iostream>

using namespace std;

class Base
{
public:
int f(int b, int c=0)
{
cout<<"Base::f"<<endl;
}
};

class Derived:public Base
{
public:
int f(int a=0)
{
cout<<"Derived::f"<<endl;
}

};

int main()
{
Derived a;
a.f(0);
a.f(0,1); // c++ reports an error.
}

Read the FAQ about "name hiding".

V
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top