Calling a base class method in a template virtual class hierarchy

后端 未结 2 585
野趣味
野趣味 2020-12-19 13:41

Let\'s say I have the following class hierarchy:

template< class T >
class TestBase {

public:

    virtual T const & do_foo() = 0;

};

template&l         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-19 14:19

    It will not win any awards for it's beauty, but this piece of code works as expected, without the compiler complaining.

    virtual int do_bar() {
        return ((TestBase *) this)->do_foo() + 1;
    }
    

提交回复
热议问题