2016-12-26 3 views
-1

Betrachten Sie das folgende Beispiel:Fehler bei der Initialisierung eines Mitglieds std :: Array mit einer Klammer initializer in gcc

#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; 
} 

, wenn es mit g zu kompilieren versuchen ++ 4.6.3 und -std=c++0x ich diesen Fehler:

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>&&’ 

jedoch die gleiche Klammer Initialisierung funktioniert, wenn eine Variable zu definieren:

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

Ist i t weil diese spezielle Version von gcc C++ 11 nicht vollständig implementiert oder fehlt mir etwas und das erste Beispiel ist nicht korrekt?

Antwort

1

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

Höchstwahrscheinlich ja. GCC 4.6 ist ziemlich veraltet.

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

In Bezug auf C++ 11 Syntax ist Ihr Beispiel in Ordnung. Es kompiliert bei colliru ohne Fehler oder Warnungen.

Verwandte Themen