How can I make the method of child be called: virtual keyword not working?

后端 未结 3 1916
天命终不由人
天命终不由人 2021-01-20 12:22

The following is my code,

#include
#include

using namespace std;

class TestClass
{
  public:
    virtual void test(string st1         


        
3条回答
  •  旧巷少年郎
    2021-01-20 12:58

    You need to change the parameter for a reference (or a pointer)

    void pass(TestClass &t)
    

    This way, the original object will be used.

提交回复
热议问题