gpt4 book ai didi

c++ - double[2] 错误 vector

转载 作者:太空狗 更新时间:2023-10-29 23:27:07 27 4
gpt4 key购买 nike

为什么会出现这个错误:

#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]’

如何解决?

最佳答案

你不能那样做。如前所述,数组不可复制或分配,这是 std::vector 的要求。我会推荐这个:

#include <vector>
struct point {
double x;
double y;
};

int main() {
std::vector<point> v;
}

无论如何它都会读起来更好,因为你可以这样做:

put(v[0].x, v[0].y, value);

这使得 vector 包含点(坐标?)更加明显

关于c++ - double[2] 错误 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3097445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com