bit*_*ask 0 c++ compiler-errors g++ compound-literals c++11
考虑这个最小的例子:
#include <array>
struct X {
std::array<int,2> a;
X(int i, int j) : a(std::array<int,2>{{i,j}}) {}
// ^^^^^^^^^^^^^^^^^^ ^
};
Run Code Online (Sandbox Code Playgroud)
根据其他帖子,我不应该在这种情况下明确构建一个临时的.我应该写:
X(int i, int j) : a{{i,j}} {}
Run Code Online (Sandbox Code Playgroud)
但是这个和我试过的其他几个(类似的)版本都被我的(不可否认的很老)g ++ 4.5.2拒绝了.我目前只有一个用于实验.它说:
error: could not convert ‘{{i, j}}’ to ‘std::array<int, 2ul>’
这是这个编译器实现的限制还是正在发生的事情?
问题是,很多时候,编译器版本.以下代码适用于GCC 4.7.1:
#include <array>
struct X{
std::array<int, 2> a;
X() : a{{1,2}} {}
};
int main(){
X x;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
300 次 |
| 最近记录: |