I have a class ('TestC'), which is derived from two other classes ('TestA' and 'TestB'), both of which have a virtual function with the same signature.
To make the function accessible through 'TestC', I have to tell it which version to use. This works if I explicitly overwrite the function in 'TestC' and call the version I want:
#include <iostream>
class TestA
{
public:
virtual void test() {std::cout<<"a";}
};
class TestB
{
public:
virtual void test() {std::cout<<"b";}
};
class TestC
: public TestA,public TestB
{
public:
void test() {TestB::test();}
};
int main(int argc,char *argv[])
{
TestC c;
TestA *a = static_cast<TestA*>(&c);
a->test();
c.test();
for(;;);
return EXIT_SUCCESS;
}
Output: "bb"
That's the expected result. However, I noticed that if I use the 'using' keyword, instead of overwriting the function explicitly, I get some unexpected behavior:
class TestC
: public TestA,public TestB
{
public:
using TestB::test;
};
(Everything else is the same)
Output: "ab"
Can someone explain this to me? It looks like 'test' is suddenly not virtual anymore? Is there any way to do this, without explicitly overwriting the function? (Something like "using override")