在尝试创建SceneNode时分配抽象类类型的对象

时间:2014-09-23 17:44:58

标签: c++ object c++11 abstract sfml

我遇到了一个我无法用C ++解决的问题。

我有一个名为SceneNode的类。在这个类中,没有任何虚函数,在私有成员中,我有一个unique_ptr向量和一个指向SceneNode对象的原始指针。 当尝试分配新的SceneNode时,我收到以下错误:分配抽象类类型的对象" SceneNode"。

以下是代码:

    class SceneNode : public  sf::Drawable,
                  public  sf::Transformable,
                  private sf::NonCopyable
{

    //OVERVIEW: A SceneNode is a node from the scene graph. It represents a graphical element
    //A typical SceneNode is (PARENT, CHILDREN, TRANSFORM)
    //With TRANSFORM containing several information:
    //TRANSFORM.POS = the position of this
    //TRANSFORM.ROTATION = the rotation of this

    //The transformation of this is always relative to its parent
    //Therefore, TRANSFORM.POS is the position of this, relatively to its parent


    //NB: - a SceneNode is not copyable !
    //    - It's an abstract class

public:

    //--------------------------------------------
    //Typedefs
    //--------------------------------------------
    typedef std::unique_ptr<SceneNode> UniquePtr;
    typedef sf::Vector2f               Position;

public:

    //--------------------------------------------
    //Constructors
    //--------------------------------------------
    SceneNode();
        //REQUIRES: /
        //MODIFIES: this
        //EFFECTS: initializes this with this_post.PARENT = no parent
        //         and this.CHILDREN = { ⦰ }

public:

    //--------------------------------------------
    //Public member functions
    //--------------------------------------------
    void attachChild(UniquePtr child);
        //REQUIRES: child != nullptr
        //MODIFIES: this
        //EFFECTS: if child == nullptr, stops the program;
        //         else, this_post.CHILDREN = this.CHILDREN U { child }

    UniquePtr detachChild(const SceneNode& child);
        //REQUIRES: /
        //MODIFIES: this
        //EFFECTS: if child in this.CHILDREN, this_post.CHILDREN = this.CHILDREN \ child && returns a unique_ptr to the child, don't catch it to let it being freed

    sf::Transform getWorldTransform() const;
        //REQUIRES: /
        //MODIFIES: /
        //EFFECTS: returns the absolute transformation of this

    Position getWorldPosition() const;
        //REQUIRES: /
        //MODIFIES: /
        //EFFECTS: returns the absolute position of this



private:

    //--------------------------------------------
    //Representation
    //--------------------------------------------
    SceneNode*             mParent;
    std::vector<UniquePtr> mChildren;



};`

我该怎么办?提前致谢

1 个答案:

答案 0 :(得分:3)

看来你继承自像sf::Drawable之类的抽象接口,但没有实现它们定义的纯虚函数(在Drawable的情况下是draw()函数)。如果在类中实现这些函数,则应该摆脱编译器错误。