I'm not very used to program in C++ , but I'm working in a robotics project using the Player/Stage environment, wich has a C++ library included.In this library I have some classes wich correspond to the robots and the information about them namely the
PlayerClient and
Position2dProxy classes.
As I'm working with multiple robots I have to be able to create a vector of these clients, so I can access each one by an index.
The problem is, when I try to create a vector of pointers to these classes(it has to be, because the objects themselves can't be copied) , I get some bugs in my program wich I assume to be related to bad memory management. Researching on the net I found out about smart pointers(speciffically the auto_ptr), wich is a wrapper class to common pointers that manage the memory automatically(i.e set the pointers to null when the objects they point to are destroyed ,etc).
Now I'm having problems declaring these vectors.This is what I tried:
1 2
|
vector < auto_ptr<PlayerClient> > clients ;
clients.push_back( new PlayerClient(args) ) ;
|
But that generates a compile error on the second line saying "no matching function to call".What's the correct way to create these objects?
Thank you in advance,
Luiz.