【问题标题】:Problem with boost::intrusive_ptrboost::intrusive_ptr 的问题
【发布时间】:2011-08-04 08:47:07
【问题描述】:

有一个结构体包含 intrusive_ptr 字段:

struct BranchFeedback : boost::counted_base {
  ...
  boost::intrusive_ptr<BPredState> theBPState;
};

还有一个变量被定义为

std::vector< std::vector< BPredState > >           theFetchState;

现在我已经实例化了一个对象

BranchFeedback theFeedback;

并希望将 theFetchState 分配给该字段

theFeedback.theBPState = theFetchState[anIndex][!anOne];

但是编译器会说一些错误

error: no match for ‘operator=’ in theFeedback.theBPState = .....

我该如何解决这个问题?

【问题讨论】:

    标签: boost vector assign


    【解决方案1】:

    您传递的是 BPredState,但 intrusive_ptr 仅支持 operator= 用于指向包含类型(或其他 intrusive_ptrs)的指针

    所以你可以写 theBPState = &(theFetchState[anIndex][!anOne]);或者获取元素的指针或迭代器并使用它来代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 2012-04-09
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多