使用boost::enable_shared_from_this出现不完整类型错误

9

在以下这行代码中:

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

我收到了以下错误:

error: invalid use of incomplete type struct boost::enable_shared_from_this<Symbol> /usr/include/boost/smart_ptr/shared_ptr.hpp:63: error: declaration of struct boost::enable_shared_from_this<Symbol>

你知道我为什么会遇到这个错误吗?Symbol是一个抽象类(如果这有影响)。


我想将一个shared_ptr传递给那些需要boost::shared_ptr<Symbol>的函数。我使用了https://dev59.com/-3RB5IYBdhLWcg3wH0SW中的思路。 - Abhishek Anand
1
@JerryCoffin:嗯,它是专门设计成一个基类的。 - Cat Plus Plus
1
@CatPlusPlus:哎呀——非常正确。我想在跳进去之前应该看一眼…… - Jerry Coffin
1个回答

14

哎呀,出错了。这是因为我没有包含头文件,而这个头文件 定义 了 enable_shared_from_this (它在 boost/enable_shared_from_this.hpp 中)。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接