C++11 constexpr function pass parameter

前端 未结 3 1747
旧时难觅i
旧时难觅i 2020-12-03 08:31

Consider the following code:

static constexpr int make_const(const int i){
    return i;
}

void t1(const int i)
{
    constexpr int ii = make_const(i);  //          


        
3条回答
  •  半阙折子戏
    2020-12-03 08:54

    Because t1() is not a constexpr function, the parameter i is a runtime variable... which you can't pass to a constexpr function. Constexpr expects the parameter to be known at compile time.

提交回复
热议问题