list of pointers to objects

what's wrong with this code??

static list<Body* > _bodies;

this is in a class declaration and

1
2
3
4
5
static void add_body(Body &b)
{
    Environment::_bodies.push_back(b);
}


in the implementation of the method. It gives an error
|In function `void add_body(Body&)':|
error: no matching function for call to `std::list<Body*, std::allocator<Body*> >::push_back(Body&)'|
G:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_list.h|785|note: candidates are: void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Body*, _Alloc = std::allocator<Body*>]|

what's the problem? thanks
Last edited on
It doesn't have a main function.
it does. it's just a chunk of code. Now I changed it to

1
2
3
4
static void Environment::add_body(Body &b)
{
    Environment::_bodies.push_back(b);
}


but the error is

cannot declare member function `static void Environment::add_body(Body&)' to have static linkage|
Going back to the original code;

what's wrong with this code??

static list<Body* > _bodies;

this is in a class declaration and


1
2
3
4
static void add_body(Body &b)
{
    Environment::_bodies.push_back(b) // The  list takes pointers NOT  references;
}


Topic archived. No new replies allowed.