why this error:
#include <vector>
typedef double point[2];
int main()
{
std::vector<point> x;
}
/usr/include/c++/4.3/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = double [2]]’: /usr/include/c++/4.3/bits/stl_construct.h:103: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = double (*)[2]]’ /usr/include/c++/4.3/bits/stl_construct.h:128: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator&) [with _ForwardIterator = double (*)[2], _Tp = double [2]]’ /usr/include/c++/4.3/bits/stl_vector.h:300: instantiated from ‘std::vector::~vector() [with _Tp = double [2], _Alloc = std::allocator]’ prova.cpp:8: instantiated from here /usr/include/c++/4.3/bits/stl_construct.h:88: error: request for member ‘~double [2]’ in ‘* __pointer’, which is of non-class type ‘double [2]’
how to solve?
You can't do that. As mentioned, arrays are not copyable or assignable which are requirements for std::vector. I would recommend this:
#include <vector>
struct point {
double x;
double y;
};
int main() {
std::vector<point> v;
}
It will read better anyway since you can do things like:
put(v[0].x, v[0].y, value);
which makes it more obvious this the vector contains points (coordinates?)
The only way you can solve this is to stop trying to do what you're trying to do. Arrays are not copyable or assignable.
In all honesty I didn't even know you could try to do something like this. It seems that the compiler is basically freaking the hell out. That doesn't surprise me. I don't know exactly why but I do know this will simply never work.
You should be able to, on the other hand, contain a boost::array without difficulty.
typedef boost::array<double,2> point;
You should look in the documentation to be sure I'm correct but I'm pretty sure this type is assignable and copy-constructable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With