小编g.-*_*-o.的帖子

如果我删除const,为什么调用boost :: shared_ptr不能在c ++中编译?

#include <boost/smart_ptr.hpp>

class Base {
};

class Derived : public Base {
  public:
    Derived() : Base() {}
};

void func(/*const*/ boost::shared_ptr<Base>& obj) {
}

int main() {
  boost::shared_ptr<Base> b;
  boost::shared_ptr<Derived> d;
  func(b);
  func(d);
}
Run Code Online (Sandbox Code Playgroud)

这用func的签名中的const编译,但不是没有它.该错误出现在呼叫的行中func(d);

有什么提示吗?

c++ const temporary shared-ptr

2
推荐指数
1
解决办法
203
查看次数

标签 统计

c++ ×1

const ×1

shared-ptr ×1

temporary ×1