Hi,
I'm basically brand new to using Boost. I'm trying to use a ptr_vector to handle some objects that I created.
Specifically I have defined a class Location which defines a particular node on a map (simple 2D game layout). I defined a ptr_vector to hold a set of Locations that have value to the calling function (nodes with units on them). In code :
boost::ptr_vector<Location> find_targets(int b_hash) {
boost::ptr_vector<Location> targets;
//find a node with variables row and col defining its position
targets.push_back(new Location(row,col));
//find and push more targets
return targets;
}
When I attempt to compile this, even without calling that function, I get the following error :
error C2666: 'boost::scoped_array::operator []' : 2 overloads have similar conversions boost\ptr_container\detail\scoped_deleter.hpp 81
Anyone have any ideas? I couldn't find any relevant help online, but I'll keep looking in the mean-time.
EDIT : More details
I'm using Boost 1.43.0 on Visual Studio 2005.
This is the simplest test I could make that would give this error.
#include "Location.h"
#include <boost\ptr_container\ptr_vector.hpp>
boost::ptr_vector<Location> find_targets()
{
boost::ptr_vector<Location> targets;
targets.push_back(new Location(1,1));
targets.push_back(new Location(2,1));
return targets;
}
int main(int argc, char **argv)
{
boost::ptr_vector<Location> t = find_targets();
}
And the Location class
class Location {
// variables //
private :
int _row;
int _col;
public :
// functions //
private :
public :
Location() {_row = 0;_col = 0;}
Location(int r, int c) { _row = r; _col = c;}
~Location(){};
int get_row() {return _row;}
int get_col() {return _col;}
};
The error occurs with any ptr_vector for any type T that I use. It only happens when I attempt to return a ptr_vector. It works if I return a ptr_vector*, so I'm experimenting with a wrapper class to see if that solves the issue.