Portál AbcLinuxu, 30. dubna 2025 11:20
typedef int A; template<typename T> struct X {}; int main() { X<::A> t; }Vystup gcc:
a.cpp: In function ‘int main()’: a.cpp:7:3: error: ‘<::’ cannot begin a template-argument list [-fpermissive] a.cpp:7:3: note: ‘<:’ is an alternate spelling for ‘[’. Insert whitespace between ‘<’ and ‘::’ a.cpp:7:3: note: (if you use ‘-fpermissive’ G++ will accept your code)Vystup clangu:
a.cpp:7:2: error: cannot refer to class template 'X' without a template argument list X<::A> t; ^ a.cpp:4:8: note: template is declared here struct X {}; ^ a.cpp:7:5: error: expected expression X<::A> t; ^ a.cpp:7:5: error: expected ']' a.cpp:7:3: note: to match this '[' X<::A> t; ^ 3 errors generated.Chapu ze oba prekladace nactou
<:
a povazuji to za alternativni token k [
. V draftu C++11, kapitole "2.5 Preprocessing tokens", jsem ale nasel:
— Otherwise, if the next three characters are <:: and the subsequent character is neither : nor >, the < is treated as a preprocessor token by itself and not as the first character of the alternative token <:.
Jeste nez jim pujdu reportovat chyby tak by me zajimalo jestli se opravdu oba prekladace rozhodly tohle ignorovat, nebo je tam nejaky catch... Obzvlaste me prekvapuje g++ a jeho drza hlaska "‘<::’ cannot begin a template-argument list"
Tiskni
Sdílej:
V draftu C++11Tohle je odpověď -- se
-std=c++0x
to projde std::vector<myNumber<int>>
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.