Trouble with vector and template

M

magnus.moraberg

Hi there,

Here is my code -

auto_ptr< H3D::MFInt32 > intList;
const vector<H3D::MFInt32 > intVector(10,0);
intList->setValue(intVector);

(where MFInt32 = MField< Int32 >)

Heres my error for the third line -

error: no matching function for call to ‘H3D::MFInt32::setValue(const
std::vector<H3D::MFInt32, std::allocator<H3D::MFInt32> >&)’
/usr/local/include/H3D/MField.h:547: note: candidates are: void
H3D::MField<Type>::setValue(const std::vector<PtrType,
std::allocator<_CharT> >&, int) [with Type = int]
/usr/local/include/H3D/MField.h:399: note: void
H3D::MField<Type>::setValue(typename H3D::MFieldBase<Type,
std::vector<PtrType, std::allocator<_CharT> >,
H3D::parsableMField>::size_type, const Type&, int) [with Type = int]

The two candidates are defined as follows -

inline virtual void setValue( typename BaseMField::size_type i, const
Type &v, int id = 0 );

template< class Type > void MField< Type >::setValue( const vector<
Type > &v, int id );

What am I doing wrong?

In the error message, why does it say -

error: no matching function for call to ‘H3D::MFInt32::setValue(const
std::vector<H3D::MFInt32, std::allocator<H3D::MFInt32> >&)’

even though I only have one argument?

Here's the documentation for the class -

http://www.h3dapi.org/uploads/api/H3DAPI_20/docs/H3DAPI/html/classH3D_1_1MFInt32-members.html

Hope you can help,

Barry
 
K

Kai-Uwe Bux

auto_ptr< H3D::MFInt32 > intList;

That's a weird name: Why is this auto_ptr to an H3D::MFInt32 a "list"?
const vector<H3D::MFInt32 > intVector(10,0);
intList->setValue(intVector);

Does H3D::MFInt32 have a method "setValue" that takes a vector of
H3D::MFInt32 as an argument? It would sound a little strange to assign a
vector to an int: what should happen if the vector is empty? what should
happen if it has more than one element?

More than likely, you did not mean what you wrote.


[snip]


Best

Kai-Uwe Bux
 
Joined
Mar 27, 2009
Messages
8
Reaction score
0
> auto_ptr< H3D::MFInt32 > intList;
> const vector<H3D::MFInt32 > intVector(10,0);
> intList->setValue(intVector);

I'm assuming here:
"auto_ptr" seems to be a sort of pointer-like object, and the variable is names "list" because you probably mean to use it as an array - so it should probably point to the first value of the array it represents.

It also seems like you're trying to make this "array" be a representation of the vector "intVector".

So I think what you should actually write is either
intList->setValue(&intVector[0]); // I just passed the pointer pointing to the first cell of the vector

or, less likely,
intList->setValue(intVector->begin()); // same as before, but for a different implementation of "auto_ptr"

Hope this helped...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top