2013-01-07 18 views
6

Kompilując następujący kod źródłowy z gcc nie ma żadnych błędów/ostrzeżeń:C++ 11: parametr szablonu redefiniuje domyślnym argumentem

template< typename T = int > T func(); 
template< typename T = int > T func(); 

Kiedy skompilować ten sam kod źródłowy z brzękiem ++, mam następujący błąd :

redeftempparam.cc:2:24: error: template parameter redefines default argument 
template< typename T = int > T func(); 
        ^
redeftempparam.cc:1:24: note: previous default template argument defined here 
template< typename T = int > T func(); 
        ^
1 error generated. 

poleceń do kompilacji

[clang++|g++] -Wall -Werror -std=c++11 redeftempparam.cc 

(informacja wersji: gcc 4.7.2, szczęk ver Sion 3.3 (trunk 171722))

Moje pytanie:

Czy ten rodzaj redefinicji dozwolone? Jeśli nie: czy możesz wskazać mi odpowiedni punkt w standardzie C++?

Odpowiedz

9

§14.1.12:

A template-parameter shall not be given default arguments by two different declarations in the same scope.

[Example:

template<class T = int> class X; 
template<class T = int> class X { /∗... ∗/ }; // error 

— end example ]

+3

Co oznacza: To nie jest dozwolone i brzęk ++ jest poprawna. Dziękuję Ci bardzo! –

Powiązane problemy