[英]Clang++ non-static data member initialization error? C++11
I can't seem to figure out what Clang is saying or whether it's right as G++-4.7 seems to compile it fine. 我似乎无法弄清楚Clang在说什么或它是否正确,因为G ++-4.7似乎可以很好地编译它。
The error comes from trying to initialize std::uniform_int_distribution
with curly braces for a non-static member. 错误来自尝试为非静态成员使用大括号初始化
std::uniform_int_distribution
。
The following fails ( token_count
is a template parameter): std::uniform_int_distribution<Int> random_dist{0, token_count-1};
以下失败(
token_count
是模板参数): std::uniform_int_distribution<Int> random_dist{0, token_count-1};
with the error: 与错误:
error: chosen constructor is explicit in copy-initialization
std::uniform_int_distribution<Int> random_dist{0, b-1};
^~~~~~~~
/usr/include/c++/v1/algorithm:2644:14: note: constructor declared here
explicit uniform_int_distribution(result_type __a = 0,
I can, however, initialize it by doing this: 但是,我可以通过执行以下操作将其初始化:
std::uniform_int_distribution<Int> random_dist = std::uniform_int_distribution<Int>(0, token_count - 1);
I am using the following command to compile it: clang++ -std=c++11 -stdlib=libc++ -lc++abi
with Clang-3.2. 我正在使用以下命令进行编译:
clang++ -std=c++11 -stdlib=libc++ -lc++abi
和Clang-3.2。
Output of clang -v
: clang -v
输出:
clang version 3.2 (trunk 157320)
Target: x86_64-unknown-linux-gnu
Thread model: posix
You probably have a version of clang that does not yet implement generalized initializers. 您可能拥有尚未实现通用初始化程序的clang版本。 Tip-of-trunk clang compiles your code.
行李箱小提示会编译您的代码。 You can check for this feature with:
您可以使用以下方法检查此功能:
#if __has_feature(cxx_generalized_initializers)
Here's the list of features you can check for: 以下是您可以检查的功能列表:
http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 http://clang.llvm.org/docs/LanguageExtensions.html#cxx11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.