Thread: C++ compile problem

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    7

    Question C++ compile problem

    I have a compile problem here.
    I have a vector declared as:

    Code:
    std::vector<CGameObject> _vGameObjects;
    CGameObject is an abstract class.

    Code:
    _vGameObjects.push_back(_paddle);
    In the code above I want to push a _paddle object, which is an instance of a concrete object derived from the CGameObject.
    The compiler (VC++ 6.0) generates an error and a series of warnings:

    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : error C2259: 'CGameObject' : cannot instantiate abstract class due to following members:
    f:\projects\simple game\game1\src\cgameobject.h(33) : see declaration of 'CGameObject'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled
    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : warning C4259: 'void __thiscall CGameObject::InitBoundingBoxes(void)' : pure virtual function was not defined
    f:\projects\simple game\game1\src\cgameobject.h(51) : see declaration of 'InitBoundingBoxes'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled
    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : warning C4259: 'class std::vector<struct BBox,class std::allocator<struct BBox> > &__thiscall CGameObject::BoundingBoxes(void)' : pure virtual function was not defined
    f:\projects\simple game\game1\src\cgameobject.h(59) : see declaration of 'BoundingBoxes'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled
    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : error C2259: 'CGameObject' : cannot instantiate abstract class due to following members:
    f:\projects\simple game\game1\src\cgameobject.h(33) : see declaration of 'CGameObject'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled
    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : warning C4259: 'void __thiscall CGameObject::InitBoundingBoxes(void)' : pure virtual function was not defined
    f:\projects\simple game\game1\src\cgameobject.h(51) : see declaration of 'InitBoundingBoxes'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled
    c:\program files\microsoft visual studio\vc98\include\xmemory(34) : warning C4259: 'class std::vector<struct BBox,class std::allocator<struct BBox> > &__thiscall CGameObject::BoundingBoxes(void)' : pure virtual function was not defined
    f:\projects\simple game\game1\src\cgameobject.h(59) : see declaration of 'BoundingBoxes'
    c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CGameObject *,const class CGameObject &)' being compiled


    Any suggestions? Thanks!

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Make sure you define all your abstract methods somewhere, and you could use a vector of pointers to CGameObject rather than the objects themeselves as the vector implementation is probably trying to call the abstract constructor.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    You cannot create an abstract calss object. Use pointers as Sorensen suggested

    std::vector<CGameObject*> _vGameObjects;

    _vGameObjects->push_back(_paddle);

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    7
    Thanks to both of you!

    I was wondering if I could use references instead of pointers. Is there any significative difference?

    ... on a second thought, it does not compile if I try using references... the pointer solution just works
    Last edited by Rhuantavan; 06-15-2002 at 03:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-14-2008, 02:35 PM
  2. compile problem
    By chintugavali in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2008, 12:16 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  5. size of Object c++ compile problem
    By micha_mondeli in forum C++ Programming
    Replies: 5
    Last Post: 04-06-2005, 01:20 PM