gpt4 book ai didi

c++ - 上的 clang++ 错误

转载 作者:行者123 更新时间:2023-11-30 05:23:05 26 4
gpt4 key购买 nike

编译包含 <experimental/any> 的代码时出现错误.

main.cpp 中的代码:

#include <experimental/any>
int main() { }

编译这个(clang 版本是 3.9):

clang++ main.cpp -o main -std=c++1z

编译后报错:

In file included from main.cpp:2:
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:364:34: error:
no template named '__any_caster'; did you mean 'any_cast'?
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:361:30: note:
'any_cast' declared here
inline const _ValueType* any_cast(const any* __any) noexcept
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:372:34: error:
no template named '__any_caster'; did you mean 'any_cast'?
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:369:24: note:
'any_cast' declared here
inline _ValueType* any_cast(any* __any) noexcept
^
2 errors generated.

最佳答案

作为@chriscomments中提到:

You could try with libc++. Perhaps there's an incompatibility with Clang in libstdc++'s new header.

事实证明这是真的。 Clang 3.9 仍处于实验阶段,因此它使用实验性 header ,包括实验性 C++ 标准库。默认情况下,它由 GCC 提供,因此 GCC 实现与 Clang 实现之间存在不兼容问题。

关于c++ - <experimental/any> 上的 clang++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352592/

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