相关疑难解决方法(0)

C++ 11中是否有一个范围类用于基于范围的循环?

我发现自己刚刚写了这篇文章:

template <long int T_begin, long int T_end>
class range_class {
 public:
   class iterator {
      friend class range_class;
    public:
      long int operator *() const { return i_; }
      const iterator &operator ++() { ++i_; return *this; }
      iterator operator ++(int) { iterator copy(*this); ++i_; return copy; }

      bool operator ==(const iterator &other) const { return i_ == other.i_; }
      bool operator !=(const iterator &other) const { return i_ != other.i_; }

    protected:
      iterator(long int start) : i_ (start) { } …
Run Code Online (Sandbox Code Playgroud)

c++ std c++11

99
推荐指数
3
解决办法
4万
查看次数

如何获得枚举的基本类型?

声明如下:

enum DrawBoldMode : unsigned
{
    DBM_NONE =              0,
    DBM_ITEM =              1<<0,   // bold just the nearest line
    DBM_SECTION =           1<<1,   // bold all lines in the same section
    DBM_LINETYPE =          1<<2,   // bold all lines of the same line type
    DBM_POINTAGE =          1<<3,   // bold all lines of the same line type
};
Run Code Online (Sandbox Code Playgroud)

如何导出DrawBoldMode的基础类型(即无符号)?

c++ templates c++11

10
推荐指数
2
解决办法
1439
查看次数

C++ 11的构造函数中的花括号参数是什么

我从一些算法书籍中读到了一个Queue的实现,有一个对我来说是新的/有趣的片段,我不明白.我认为它是像C++ 11中的向量初始化列表一样的新东西,但由于代码的上下文,我不是那么自信.任何人都可以光明或提供一些参考?

template <typename T>
class Queue {
    private:
        size_t head, tail, count;
        vector<T> data;
    public:
        Queue(const size_t &cap=8) : head(0),tail(0),count(0),data({cap}) {}
        //... more interfaces
        //...
}
Run Code Online (Sandbox Code Playgroud)

可疑部分是数据({cap}),这是什么?它将矢量调整为容量上限?(显然,代码的作者打算在构造数据时给出数据大小.)

编辑:在阅读第一个答案和测试后,我们知道该书在代码段中有错误.它打算给出一个初始上限,但它使用了错误的{}.

c++ c++11

7
推荐指数
1
解决办法
4070
查看次数

标签 统计

c++ ×3

c++11 ×3

std ×1

templates ×1