[英]“list iterator not dereferencable” on creation of object
I'm creating a computer graphics project using C++ and QT in visual studio. 我正在Visual Studio中使用C ++和QT创建计算机图形项目。
The line I'm getting this error on is 我收到此错误的行是
quad *bodyQuad = &quad(bodyTri1, bodyTri2);
in the following method: 在以下方法中:
void MyGLWidget::createCharacter1(tree *t, node *root) {
triangle bodyTri1 = triangle(vec3(4, 0, 0), vec3(-1, 1, 0));
triangle bodyTri2 = triangle(vec3(-6, 0, 0), vec3(-1, -1, 0));
bodyTri2 = *bodyTri2.applyTransform(mat3::translation2D(5, 1));
quad *bodyQuad = &quad(bodyTri1, bodyTri2);
root = new node(bodyQuad, 2);
}
triangle
and quad
are both derived from a virtual shape
class. triangle
和quad
都从虚拟shape
类派生。 The shape
class has a std::list
in it for storing vertices. shape
类中有一个std::list
,用于存储顶点。
node
also has an std::list
for storing its children. node
还有一个std::list
用于存储其子node
。
In the constructor of both triangle
and quad
the vertices are added to the list 在
triangle
和quad
的构造函数中,将顶点添加到列表中
triangle::triangle(const vec3& vector1, const vec3& vector2) {
numTriangles = 1;
isOneColor = true;
vec3 origin = vec3(0, 0, 1);// '1' to signify a point
data = mat3(vector1, vector2, origin);
data = data.transpose();
//push "origin" vertex
vertices.push_back(data[2]);
//make sure point/vector convention followed, and push "base" vertex
vertices.push_back(data[0] + vec3(0, 0, 1));
//make sure point/vector convention followed, and push "height" vertex
vertices.push_back(data[1] + vec3(0, 0, 1));
}
quad::quad(triangle triangle1, triangle triangle2) {
numTriangles = 2;
isOneColor = true;
data[0] = triangle1;
data[1] = triangle2;
std::list<vec3> tri1Vertices = data[0].getVertices();
std::list<vec3> tri2Vertices = data[1].getVertices();
for (size_t i = 0; i < tri1Vertices.size(); i++) {
vertices.push_back(tri1Vertices.front());
tri1Vertices.pop_front();
}
for (size_t i = 0; i < tri2Vertices.size(); i++) {
vertices.push_back(tri2Vertices.front());
tri2Vertices.pop_front();
}
}
My problem was that my applyTransform()
was returning a shape
pointer, but in my return statement I was simply dereferencing &
a temp variable used in applyTransform()
instead of using the new
keyword. 我的问题是我的
applyTransform()
返回一个shape
指针,但是在我的return语句中,我只是取消引用&
一个applyTransform()
中使用的临时变量,而不是使用new
关键字。
Thank you to everyone who helped. 谢谢所有帮助的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.