0
我有一个我无法用C++解决的问题。尝试创建SceneNode时分配抽象类类型的对象
我有一个叫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;
};`
我能做些什么?在此先感谢
做任何'sf :: Drawable','sf :: Transformable'或'sf :: NonCopyable'都有纯粹的虚拟函数,你没有重写? – clcto 2014-09-23 17:49:16
要回答我自己的问题,是的,他们的确如此:http://sfml-dev.org/documentation/2.0/classsf_1_1Drawable.php – clcto 2014-09-23 17:52:38
@clcto是的 - 所有的都是SFML类,Drawable需要一个Draw() – Conduit 2014-09-23 17:52:55