if a method is overloaded with a const version, in the case thateither one is okay, which shall the

Y

yuyang08

Dear all,

I have a question on the const methods. If a method is overloaded with
a const version, in the case that either one is okay (for example, the
following code), which shall the compiler pick? Could you tell which
section of the C++ standard specifies this?

Many thanks!

-Andy

#include <iostream>
using namespace std;

class A{
public:
int foo() const { return 6; }
int foo() { return 5; }
public:
int x;
};

int main()
{
A ca;
int c = ca.foo();
cout << "c = " << c << endl;
return 0;
}
 

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,013
Latest member
KatriceSwa

Latest Threads

Top