我想做一个通用函数来搜索节点中的类类型并返回它的地址。它被定义下面Coin3D中未处理的异常错误(Open Inventor)
SoNode* searchandgive(SoType searchtype, SoNode* searchnode)
{
SoSearchAction mysearch;
mysearch.setType(searchtype);
mysearch.setInterest(SoSearchAction::FIRST);
mysearch.apply(searchnode);
if (mysearch.getPath() == NULL) {
std::cout<<"No property of this type was found";
}
SoPath* mypath=mysearch.getPath();
return mypath->getTail();
}
但是当我通过像SoCoordinate3 :: getClassTypeId()的搜索类型和节点要搜索senode如下给出:
SoCoordinate3 * mycoords=(SoCoordinate3*) searchandgive(SoCoordinate3::getClassTypeId(),senode);
const SbVec3f *s=mycoords->point.getValues(0);
std::cout<<" " <<s->getValue()[25]; // Some point
但最后一行正在产生未处理的异常错误。请告诉我在这里做错了什么。最后一行是有效的,因为在函数的作用域内写入的内容相同,但不在这里。
你为什么不检查空指针返回? –