C++ member function virtual override and overload at the same time

前端 未结 3 675
忘了有多久
忘了有多久 2020-12-13 04:26

If I have a code like this:

struct A {
  virtual void f(int) {}
  virtual void f(void*) {}
};

struct B : public A {
  void f(int) {}
};

struct C : public B         


        
3条回答
  •  旧巷少年郎
    2020-12-13 05:10

    Well I think first of all you did not understand what virtual mechanism or polymorhism. When the polymorphism is achieved only by using object pointers. I think you are new to c++. Without using object pointers then there is no meaning of polymorphism or virtual keyword use base class pointer and assign the desired derived class objects to it. Then call and try it.

提交回复
热议问题