Is there a way to forward declare covariance?

后端 未结 4 1461
别跟我提以往
别跟我提以往 2021-02-19 02:02

Suppose I have these abstract classes Foo and Bar:

class Foo;
class Bar;

class Foo
{
public:
  virtual Bar* bar() = 0;
};

class Bar
{         


        
4条回答
  •  爱一瞬间的悲伤
    2021-02-19 02:21

    Doesn't static polymorphism solve your problem? Feeding the base class with the derived class through template argument? So the base class will know the derivative Type and declare a proper virtual?

提交回复
热议问题