gpt4 book ai didi

c++ - clang++ 中的 std::underlying_type 支持

转载 作者:行者123 更新时间:2023-11-30 03:49:18 27 4
gpt4 key购买 nike

我假设应该通过 -std=c++11 开关在 clang++ 中启用 C++ 复合类型变更支持。但是我无法使用 clang 编译这段代码:

#include <iostream>
#include <type_traits>

enum class A {a,b,c};
enum B : short {x,y,z};

int main() {

typedef std::underlying_type<A>::type A_under; // int
typedef std::underlying_type<B>::type B_under; // short

std::cout << std::boolalpha;
std::cout << "typedefs of int:" << std::endl;

std::cout << "A_under: " << std::is_same<int,A_under>::value << std::endl;
std::cout << "B_under: " << std::is_same<int,B_under>::value << std::endl;

return 0;
}

我收到这个错误:

$ clang++ underlyingtype.cpp -std=c++11
underlyingtype.cpp:10:16: error: no type named 'underlying_type' in namespace 'std'
typedef std::underlying_type<A>::type A_under; // int

知道为什么会这样吗?

更多信息:

lashgar@fengdu:~/code$ clang++ --version
clang version 3.8.0 (http://llvm.org/git/clang.git 1ad799453a2e54cfded555a03fd58dbd102c5f62) (http://llvm.org/git/llvm.git af5ff60200812e518c72a022fb4c66b9a5f0116a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/lashgar/opt/llvm/bin

最佳答案

这是一个指向 online compiler with libstdc++ 4.6.4 的链接重现此错误。

只需确保获取标准库的版本即可。 libstdc++ 4.7 及更高版本或 libc++ 3.0 及更高版本应该可以正常工作。

关于c++ - clang++ 中的 std::underlying_type 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32637051/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com