我使用shared_ptr
with 构造这样的对象:
std::tr1::shared_ptr<RawClusterBase> rawCluster(new RawClusterBase());
// ...
rawCluster->addLabel(p->userFriendlyTerms());
// ...
const TokenizedDocument * tokenizedDoc
= (TokenizedDocument *)documents.at(i);
const RawDocument * rawDoc
= dynamic_cast<const RawDocument *>(tokenizedDoc->getProperty(
TokenizedDocument::_PROPERTY_RAW_DOCUMENT));
rawCluster->addDocument(rawDoc);
我在以下行遇到分段错误dynamic_cast
:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b92429 in __dynamic_cast () from /usr/lib/libstdc++.so.6
(gdb) backtrace
#0 0x00007ffff7b92429 in __dynamic_cast () from /usr/lib/libstdc++.so.6
#1 0x0000000000444aa5 in main (argc=1, argv=0x7fffffffe258) at clustering/document_test.cpp:271
谁能给我一个指示如何解决这个问题?我的项目中有另一个部分dynamic_cast
用于分析子类。我也打算在shared_ptr
那里使用,但我担心我会遇到同样的麻烦。是dynamic_cast
不是一起工作shared_ptr
?
非常感谢任何提示!