【发布时间】:2016-09-08 21:22:45
【问题描述】:
如果我在这样的类中定义具有相同名称和参数但返回类型不同的成员函数是否有效:
class Test {
public:
int a;
double b;
}
class Foo {
private:
Test t;
public:
inline Test &getTest() {
return t;
}
inline const Test &getTest() const {
return t;
}
}
如果我们有以下代码,会调用哪个成员函数?
Foo foo; // suppose foo has been initialized
Test& t1 = foo.getTest();
const Test& t2 = foo.getTest();
【问题讨论】:
-
你的函数没有相同的签名...
标签: c++