请选择 进入手机版 | 继续访问电脑版

c++ 编译错误

编译器工具链 编译器工具链 1189 人阅读 | 1 人回复 | 2022-03-10

g++ 8.3
```cpp
#include <math.h>
#include <stdio.h>
bool is_a = false;

template<typename T>
class A
{
public:
void fun()
{
         constexpr bool is_a = std::is_same_v<T,int>;

         auto fun2=[&,is_a] () {
                 if constexpr (is_a)
                         return 1;
                 return 0;
         };
         printf("%d\n",fun2());

}
};

int main()
{
         A<int> a;
         a.fun();

}

```

g++ 3.cpp  --std=c++17
3.cpp: In lambda function:
3.cpp:14:21: error: lambda capture of 'is_a' is not a constant expression

回复

使用道具 举报

回答|共 1 个

TecSupport

发表于 2022-5-16 11:20:02 | 显示全部楼层

【提示:论坛功能管控受限,建议您移步“申威社区-助力申威-问题反馈”反馈问题,谢谢】
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则