I want to do something like this

template <class T>
	vector<T> DereferenceVector(vector<T*> &PointerVec)
	{
		vector<T> ObjectVec;
		for(unsigned int i = 0; i < PointerVec.size(); i++)
			ObjectVec.push_back(*PointerVec[i]);

		return ObjectVec;
	}

and call it with

void TestDereferenceVector()
{
	vector<double*> a(10);

	vector<double> b = DereferenceVector(a);
}

That seems to work. But if I do

void TestDereferenceVector()
{
	vector<vgl_point_3d<double>*> a(10);

	vector<vgl_point_3d<double> > b = DereferenceVector(a);
}
/media/portable/Projects/src/ModelFile/ModelFile.h:304: error: no matching function for call to 'DereferenceVector(const std::vector<vgl_point_3d<double>*, std::allocator<vgl_point_3d<double>*> >&)'

Why would it not work with a more complex type?

Thanks,

Dave

Interesting, it works if I make the vector of pointers const:

template <class T>
vector<T> DereferenceVector(const vector<T*> &PointerVec)

So I guess it was just a const problem and I thought I was doing something wrong with the template!

Also, I edited the original post once, but then I tried to edit it again but there was no "Edit" button - why is that?

Dave

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.