c++ - 如何使用 dynamic_bitset<> 复制位

标签 c++ boost

我有这个功能:

void SetCode(dynamic_bitset<> * c) {  
    this->_code = c;  
    this->_size = c->size();  
}

上面写着:this->_code = c,我想复制一份c并把它放在this->_code >。

我该怎么做?

最佳答案

鉴于this->_code是一样的dynamic_bitset<>作为c .您可以只使用赋值运算符(这需要 _code 已经初始化,即 new ed):

*_code = *c;

您可能应该从 this->_code 的类型中删除指针并在参数中使用引用:

class A {
public:
  void foo (boost::dynamic_bitset<T, U>& c)
  {
    _code = c;
  }

private:
  boost::dynamic_bitset<T, U> _code;
};

您没有为 dynamic_bitset 提供任何模板参数所以我只选择了两个假的。

关于c++ - 如何使用 dynamic_bitset<> 复制位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12941232/

相关文章:

C++数字猜谜游戏 - 来自if语句的循环文本墙

c++ - "function"类型的优点是什么(不是 "pointer to function")

c++ - 使用boost的shared_ptr管理C类型生命周期?

c++ - 在基类中调用 shared_from_this() 时的 bad_weak_ptr

c++ - boost 任何使用

c++ - C++ 标准模板库中 std::sort 的空间复杂度是多少?

c++ - 多路进程间通信

继承模板类中的 C++ 编译器错误

c++ - 如何为类的每个方法添加计时器?

c++ - boost::io_service post 方法是否会导致新的分配?