CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Threaded View

  1. #1
    Join Date
    Jan 2008
    Posts
    78

    Abstract class and vector issue

    I have an abstract class, SceneObject declared as follow:
    PHP Code:
    #ifndef SCENE_OBJECT_H
    #define SCENE_OBJECT_H

    #include "Application.h"

    class SceneObject{

    public:
        
    SceneObject(void);
        
    virtual ~SceneObject(void);

    public:
        
    virtual void update(Applicationapp)=0;
        
    virtual void render(Applicationapp)=0;
    };
    #endif // SCENE_OBJECT_H 
    There are two more that derive from the above, an implementation...
    PHP Code:
    #ifndef GROUP_H
    #define GROUP_H

    #include <vector>
    #include "SceneObject.h"

    class Group : public SceneObject{

    private:
        
    std::vector<SceneObjectchildren;

    public:
        
    Group(void);
        ~
    Group(void);

    public:
        
    void update(Applicationapp);
        
    void render(Applicationapp);
    };
    #endif // GROUP_H 
    ... and a supposed more specialized abstract class:
    PHP Code:
    #ifndef ACTOR_H
    #define ACTOR_H

    #include "SceneObject.h"

    class Actor SceneObject{

    public:
        
    Actor(void);
        ~
    Actor(void);

    public:
        
    virtual void update(Applicationapp)=0;
        
    virtual void render(Applicationapp)=0;
    };
    #endif // ACTOR_H 
    As you can see, Group has a vector of SceneObjects that will eventually contain Groups or Actors.
    On compile, the compiler yields
    Code:
    c:\program files\microsoft visual studio 9.0\vc\include\vector(716) : error C2259: 'SceneObject' : cannot instantiate abstract class
            due to following members:
            'void SceneObject::update(Application *)' : is abstract
            c:\documents and settings\alexandre\my documents\visual studio 2008\projects\ocaso\ocaso\sceneobject.h(13) : see declaration of 'SceneObject::update'
            'void SceneObject::render(Application *)' : is abstract
            c:\documents and settings\alexandre\my documents\visual studio 2008\projects\ocaso\ocaso\sceneobject.h(14) : see declaration of 'SceneObject::render'
            c:\documents and settings\alexandre\my documents\visual studio 2008\projects\ocaso\ocaso\group.h(10) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
            with
            [
                _Ty=SceneObject
            ]
    Any help is welcome.
    Last edited by alexin; February 13th, 2008 at 01:58 PM. Reason: Correction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured