2016-12-26 75 views
-1

考慮下面的例子:嘗試與克++ 4.6.3和-std=c++0x編譯它出現此錯誤時錯誤當構件的std ::陣列

#include <array> 

template <typename T> 
struct A { 
    A() {} 
}; 

typedef A<int> B; 

struct S { 
    std::array<B, 1> b; 

    S() : b{{B()}} {} 
}; 

int main() { 
    S s; 
} 

test.cc: In constructor ‘S::S()’: 
test.cc:13:16: error: no matching function for call to ‘std::array<A<int>, 1ul>::array(<brace-enclosed initializer list>)’ 
test.cc:13:16: note: candidates are: 
/usr/include/c++/4.6/array:60:12: note: std::array<A<int>, 1ul>::array() 
/usr/include/c++/4.6/array:60:12: note: candidate expects 0 arguments, 1 provided 
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(const std::array<A<int>, 1ul>&) 
/usr/include/c++/4.6/array:60:12: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::array<A<int>, 1ul>&’ 
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(std::array<A<int>, 1ul>&&) 
/usr/include/c++/4.6/array:60:12: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::array<A<int>, 1ul>&&’ 

然而,定義一個變量時同樣梅開二度的初始化工作:

std::array<B, 1> b{{B()}}; 

是我因爲這個特定版本的gcc沒有完全實現C++ 11,或者我錯過了一些東西,第一個例子不正確?

回答

1

Is it because this particular version of gcc doesn't fully implement C++11

最有可能的是。 GCC 4.6非常過時。

or am I missing something and the first example is not correct?

關於C++ 11語法,你的例子很好。它編譯在colliru沒有錯誤或警告。