我有一个名为 Test 的类,它继承了 TopoDS_Face 类。已经从这个问题中得到了一些提示,但是......
// Test.h
class Test : public TopoDS_Face
{
public:
void operator = (const TopoDS_Face& base_)
{
TopoDS_Face::operator=(base_);
}
}
// testmain.cpp
...
int main() {
//extract faces from IGES face
for (int i = 1; i <= nbs; i++) {
TopoDS_Shape shape = myIgesReader.Shape(i);
TopoDS_Face& face = static_cast<TopoDS_Face&>(TopoDS::Face(shape));
Test *test;
// tried each of these also and did not succeed
// Test *test = dynamic_cast<Test*>(&face);
// test = &face
test->TopoDS_Face::operator=(face);
...
}
}
main 中的代码从 IGES 文件中提取人脸,并将每个人脸对象分配给 main 中创建的测试对象。编译进行得很好,但 valgrind 抱怨以下错误:
==21718== Use of uninitialised value of size 8
==21718== at 0x9B0946C: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
==21718== Use of uninitialised value of size 8
==21718== at 0x9B09431: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
==21718== Invalid read of size 4
==21718== at 0x9B0943C: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718== Address 0x75eb394801c38350 is not stack'd, malloc'd or (recently) free'd
==21718==
==21718==
==21718== Process terminating with default action of signal 11 (SIGSEGV)
==21718== General Protection Fault
==21718== at 0x9B0943C: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
我需要帮助解决程序。提前致谢。