friend-Template-Funktion und Default Argument
-
Hallo zusammen,
Ich habe:class foo { template <typename T = int> friend T func(); }; template <typename T = int> T func() { return T(); }Code::Blocks meckert:
...\Programmierung\Projekte\MyLibs-Test\main.cpp:14:3: error: redeclaration of friend 'template<class T> T func()' may not have default template arguments ...\Programmierung\Projekte\MyLibs-Test\main.cpp:10:14: error: 'template<class T> T func()' previously declared hereWie geht das, was ich meine?
lg
Nathan
-
Vorher bekannt machen?
template <typename T = int> T func(); class foo { template <typename T> friend T func(); }; template <typename T> T func() { return T(); }
-
Ähm...

OK, danke.
-
ScottZhang schrieb:
Vorher bekannt machen?
oder später
class foo { template <typename T> friend T func(); }; template <typename T=int> T func() { return T(); }
-
Darauf wäre ich selber auch gekommen...
-
Nathan schrieb:
Darauf wäre ich selber auch gekommen...
Dummerweise ein Bug. Wie auch die ursprüngliche Fehlermeldung irreführend ist.
n3337 14.1/9 schrieb:
[...]If a friend function template declaration specifies a default template-argument, that declaration shall be a definition and shall be the only declaration of the function template in the translation unit.
Das hätte der Compiler im ursprünglichen Code bemängeln müssen.
-
Ach so.