ノード内のクラス タイプを検索し、そのアドレスを返す一般的な関数を作成したかったのです。以下に定義されています
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
しかし、最後の行は未処理の例外エラーを生成しています。ここで何が間違っているのか教えてください。関数のスコープ内に書かれたものは機能しますが、ここでは機能しないため、最後の行は有効です。