【问题标题】:incomplete type error on using boost::enable_shared_from_this使用 boost::enable_shared_from_this 时出现不完整的类型错误
【发布时间】:2012-05-17 14:13:30
【问题描述】:

在下面一行

class Symbol : public boost::enable_shared_from_this<Symbol> {

我得到错误:

错误:不完整类型的无效使用struct boost::enable_shared_from_this<Symbol> /usr/include/boost/smart_ptr/shared_ptr.hpp:63: 错误:struct boost::enable_shared_from_this<Symbol>的声明

知道为什么我会收到此错误。 Symbol 是一个抽象类(如果重要的话)

【问题讨论】:

  • 我想将 shared_ptr 传递给 this 给需要 boost::shared_ptr 的函数。我使用了stackoverflow.com/questions/712279/…的想法
  • @JerryCoffin:呃,它专门被设计成一个基类。
  • @CatPlusPlus:糟糕——非常正确。我想我应该在我跳进去之前看看......

标签: c++ shared-ptr


【解决方案1】:

哎呀。错误是因为我没有包含 定义 enable_shared_from_this 的标头 (这是 boost/enable_shared_from_this.hpp)。

它只是在 /usr/include/boost/smart_ptr/shared_ptr.hpp 中声明

【讨论】:

    猜你喜欢
    • 2021-02-19
    • 1970-01-01
    • 2013-12-01
    • 2015-10-27
    • 2014-11-22
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多