gnuradio c++ connect self() throw bad_weak_ptr
gnuradio c++ connect self() throw bad_weak_ptr
我想在我的构造函数中调用一些代码
connect(self() , 0 , filter , 0);
connect(filter , 0 , self() , 0);
但我得到例外
在抛出"boost::exception_detail::clone_impl>"实例后终止调用
我做下一个
my_filter::sptr
my_filter::make(unsigned int interpolation,
unsigned int decimation) {
auto ptr = gnuradio::get_initial_sptr(new my_filter
(interpolation, decimation));
ptr->wire();
return ptr;
}
和方法线材
void my_filter::wire() {
connect(self(), 0, resampler, 0);
connect(resampler, 0, self(), 0);
}
但是我得到错误
Terminate called after throwing an instance of 'std::invalid_argument'
what(): sptr_magic: invalid pointer!
what(): tr1::bad_weak_ptr
我该如何改进?
当引发此异常时读取:
std::bad_weak_ptr 是作为异常抛出的对象的类型 将 std::shared_ptr 的构造函数 std::weak_ptr 作为 参数,当 std::weak_ptr 引用已删除的对象时。
很可能您的self()
只是调用shared_from_this()
并且没有指向当前对象的shared_ptr
,因为您正处于构建时间,因此shared_from_this()
必须抛出异常。
两个修复它使用模式两步初始化。
std::tr1::shared_ptr<YourCalsss> YourCalsss::Create() // static method
{
auto result = std::tr1::shared_ptr<YourCalsss>(new YourCalsss);
result->init(); // inside that you will do a connect
return result;
}
附言。我假设您正在使用 C++03 和tr1
因为错误信息提供了此线索。
相关文章:
- 为什么"weak.lock()"返回"nullptr" "auto weak=std::make_shared<int>(42);"的定义?
- 使用来自 Excel VBA 的 C++ dll 时"Bad DLL calling convention" - 如何解决?
- C++17 编解码器在将标准::字符串转换为标准::字符串时抛出"bad conversion"
- 对于代理容器上的迭代器来说,"least bad implementation"可能是什么?
- 为什么使用模板生成的函数具有"weak"符号类型?
- 获取错误:在抛出"std::bad::alloc"的实例后终止调用 what(): std::bad_alloc
- 为什么 GetSystemMetrics (SM_CXVIRTUALSCREEN) 返回'bad'值?
- 将 lambda 传递给 STL 集时出错"bad function call"
- 新的 C++14 位分隔符处"Bad Character" Eclipse Oxygen 错误
- 使用 #define 被认为是"bad practice"吗?
- "400 Bad request"使用 OpenSSL BIO 进行请求时
- 解密文件AES_256_CBC返回"bad decrypt"错误
- 在C++流中,eof(),fail(),bad()和good()有什么区别
- 为什么原始指针没有"weak pointer"?还是有?
- make / gcc:"bad build"的可能原因是什么?
- 什么是地址0xbaddc0dedeadbead "Bad decode dead bead"
- 在多线程环境中,什么可能导致"bad file descriptor"?
- "std::vector"在调整大小时引发"bad allocation"异常
- 尝试使用 execp、dup2 和管道实现 shell,挂起或"bad file descriptor"
- OpenCV SVM 在火车上抛出异常,"Bad argument (There is only a single class)"