键入cast child to grandparent class

时间:2015-12-01 00:47:41

标签: c++ c++11 inheritance casting deque

当前代码:

class A { 
    // Abstract class
    ... 
};

class B : public A { 
    // Concrete class
    ... 
};

class C : public B { 
    // Concrete class
    ... 
};

class D : public C { 
    // Abstract class
    ... 
};

class E : public A {
    // Concrete class
private:
    std::deque< std::shared_ptr<A> > m_deque;

public:
    E& operator+=( std::shared_ptr<D> temp ) {
        m_deque.push_front( temp );
        ...
    }
    ...
};

尝试重载+=运算符时,我想将参数temp推送到双端队列m_deque。问题是这些类型不匹配。如何将temp推入deque m_deque

我正在尝试输入强制转换temp,但我不确定如何输入强制转换为祖父母类。

0 个答案:

没有答案