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;
}
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;
}