PDA

View Full Version : Problem with boost::array


Valheru
16th August 2007, 21:00
And probably with templates in general - I've never used them outside of Qt's :)

I am trying to pass boost::array< float, int > as a function argument, but GCC is comlaining :

/home/lawrence/Projects/modelloader/src/modelloader.h:21: error: expected a constant of type ‘int’, got ‘unsigned int’
/home/lawrence/Projects/modelloader/src/modelloader.h:22: error: type/value mismatch at argument 2 in template parameter list for ‘template<class T, unsigned int N> class boost::array’
Also, in the implementation .cpp file when I try an create a boost::array it complains :

/home/lawrence/Projects/modelloader/src/objloader.cc:81: error: ‘num_vertices’ cannot appear in a constant-expression
/home/lawrence/Projects/modelloader/src/objloader.cc:81: error: template argument 2 is invalidAlso, I tried earlier to pass it as a pointer :

boost::array< float, int > *xIs that valid syntax?

TIA.

jacek
16th August 2007, 23:50
Is that valid syntax?
No, boost::array is meant as a replacement for C-style arrays and it has a constant size that must be known at compile time: boost::array< float, 100 > *x;