Jak mogę wywołać metodę potomną: słowo kluczowe wirtualne nie działa?

Oto mój kod,

#include<iostream>
#include<string>

using namespace std;

class TestClass
{
  public:
    virtual void test(string st1, string st2);

};

class ExtendedTest: public TestClass
{
  public:
    virtual void test(string st1, string st2);
};

void TestClass::test(string st1, string st2="st2")
{
     cout << st1 << endl;
     cout << st2 << endl;
}

void ExtendedTest::test(string st1, string st2="st2")
{
     cout << "Extended: " << st1 << endl;
     cout << "Extended: " << st2 << endl;
}

void pass(TestClass t)
{
    t.test("abc","def");
}


int main()
{
   ExtendedTest et;
   pass(et);
   return 0;
}

Po uruchomieniu kodu wywoływana jest metoda („test”) klasy bazowej. Ale oczekuję, że metoda potomna zostanie wywołana, ponieważ określiłem metody jako funkcję wirtualną.

W jaki sposób można wywołać metodę klasy potomnej? Dziękuję Ci.

questionAnswers(3)

yourAnswerToTheQuestion