相关疑难解决方法(0)

为什么这个constexpr静态成员函数在被调用时不被视为constexpr?

为什么这个constexpr static//! Nah注释标识的成员函数constexpr在调用时看不到?

struct Item_id
{
    enum Enum
    {
        size, position, attributes, window_rect, max_window_size, _
    };

    static constexpr int n_items_ = _;                          // OK
    constexpr auto member_n_items() const -> int { return _; }  // OK
    static constexpr auto static_n_items() -> int { return _; } // OK
    static constexpr int so_far = n_items_;                     // OK
    #ifndef OUT_OF_CLASS
        static constexpr int bah = static_n_items();            //! Nah.
    #endif
};

constexpr auto n_ids() -> int { …
Run Code Online (Sandbox Code Playgroud)

c++ constexpr

17
推荐指数
2
解决办法
1904
查看次数

如果函数在类范围内声明,constexpr不工作

我使用的是g ++ 4.8.0,它不包含早期的constexprbug.因此下面的代码工作正常:

constexpr int size() { return 5; }
int array[size()];

int main () {}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将变量括在一个classas中static,那么它会给出编译器错误:

struct X {
  constexpr static int size() { return 5; }
  static const int array[size()]; 
};

int main () {}
Run Code Online (Sandbox Code Playgroud)

这是错误:

错误:数组'array'的大小不是整数常量表达式

禁止以constexpr这种方式使用还是使用另一个g ++ bug?

c++ compiler-errors g++ constexpr c++11

16
推荐指数
2
解决办法
4830
查看次数

标签 统计

c++ ×2

constexpr ×2

c++11 ×1

compiler-errors ×1

g++ ×1