C++ Visual Studio 2015 bug?成员函数访问不明确,使用语句重写祖先类的顺序
我是遗漏了什么,还是发现了Visual Studio bug 撇开bug不谈,使用这种类型的继承是好还是坏 GCC 4.9.0产生了我的预期结果:C++ Visual Studio 2015 bug?成员函数访问不明确,使用语句重写祖先类的顺序,c++,visual-studio,inheritance,ambiguous,using-declaration,C++,Visual Studio,Inheritance,Ambiguous,Using Declaration,我是遗漏了什么,还是发现了Visual Studio bug 撇开bug不谈,使用这种类型的继承是好还是坏 GCC 4.9.0产生了我的预期结果: base.getProperty() 1 otherBase.getProperty() 2 derivedA.getProperty() 1 derivedB.getProperty() 2 但是,VS 2015 CTP 6和VS 2013 Update 5 CTP产生了我认为不正确的结果: base.getProperty() 1 otherB
base.getProperty() 1
otherBase.getProperty() 2
derivedA.getProperty() 1
derivedB.getProperty() 2
但是,VS 2015 CTP 6和VS 2013 Update 5 CTP产生了我认为不正确的结果:
base.getProperty() 1
otherBase.getProperty() 2
derivedA.getProperty() 1
derivedB.getProperty() 1
将类derivedClassB:public-derivedClassA,otherBaseClass{更改为类derivedClassB:public-otherBaseClass,derivedClassA{产生我预期的结果。我可能遗漏了一些东西,但尽管继承自的类的顺序会影响初始化顺序,但我认为它不会影响要使用的模糊函数-特别是当有一个using语句来澄清存在的其他模糊性时
#include <iostream>
using namespace std;
class baseClass {
public:
virtual int getProperty() {
return 1;
}
};
class otherBaseClass : public baseClass {
public:
virtual int getProperty() {
return 2;
}
};
class derivedClassA : public baseClass {
public:
void someUniqueThing() {
cout << "someUniqueThing" << endl;
}
};
class derivedClassB : public derivedClassA, otherBaseClass {
public:
using otherBaseClass::getProperty;
};
int main() {
baseClass base;
cout << "base.getProperty() " << base.getProperty() << endl;
otherBaseClass otherBase;
cout << "otherBase.getProperty() " << otherBase.getProperty() << endl;
derivedClassA derivedA;
cout << "derivedA.getProperty() " << derivedA.getProperty() << endl;
derivedClassB derivedB;
cout << "derivedB.getProperty() " << derivedB.getProperty() << endl;
}
GCC是正确的。正如消息所说,由于多重继承的顺序,derivedClassA::getProperty隐藏了otherBaseClass::getProperty,尽管derivedClassB中有using语句。这应该是一个标准遵从性问题,而不是一个bug。