c++ - Visual Studio 2015 bug? Ambiguous member function access, order of ancestor classes overrides using statement -
am missing something, or did find visual studio bug?
bugs aside, using type of inheritance ok or evil?
gcc 4.9.0 produces expected results:
base.getproperty() 1 otherbase.getproperty() 2 deriveda.getproperty() 1 derivedb.getproperty() 2
but, both vs 2015 (ctp 6) , vs 2013 (update 5 ctp) produce believe incorrect results:
base.getproperty() 1 otherbase.getproperty() 2 deriveda.getproperty() 1 derivedb.getproperty() 1
changing "class derivedclassb : public derivedclassa, otherbaseclass {" "class derivedclassb : public otherbaseclass, derivedclassa {" produces expected results. missing something, although order of classes inherited affect initialization order, don't think supposed affect ambiguous function use -- when there using statement clarify otherwise present ambiguity.
#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; }
Comments
Post a Comment