|
From: | Larry I Smith |
Subject: | Re: template argument required |
Date: | Sun, 15 May 2005 17:32:33 GMT |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20050414 |
Patrick Rammelt wrote:
Larry I Smith wrote:Patrick Rammelt wrote:Hi I have just upgraded from gcc-3.3.3 to gcc-4.0.0 Trying to compile some old code I stumbled over an error. I created this short example: -------------------- gcctest.cpp ----------------------------- #include <iostream> using namespace ::std; template <class T> class A { public: A (void) {} template <class X> class A& foo (X p) { // no error without "class" cout << "template foo\n"; return(*this); } }; int main (void) { A<double> a1, a2; a1.foo(a2); // line 22: error (see below) exit(0); } --------------------------------------------------------------------no errors when compiling it with g++-3.3.3, but g++-4.0.0 (and g++-3.4.1) complaints:gcctest.cpp: In function ‘int main()’: gcctest.cpp:22: error: template argument required for ‘struct A’ gcctest.cpp:22: error: no matching function for call to ‘A<double>::foo(A<double>&)’Substituting "class A&" by just "A&" in foo it compiles without any warnings or errors (and works as expected). Does this make any sense, or is it a bug?The definition of foo() is ambiguous. Does this fix it? template <class X> class A<T> & foo (X p) { // <-- specify WHICH type of 'A' cout << "template foo\n"; return(*this); }Yes it does - Thanks! My fix was to leave away the "class", but this solution looks better. It really _looks_ better because my editor /needs/ the "class" for syntax-highlighting :-) I'm just curious: is there a reason why the keyword "class" makes a difference here - or should there occure an error either in both cases or not at all? At least I think the error-message (pointing to line 22) is a bit misleading here?!Ciao, Patrick
'class' should not be required. In fact, it may confuse the issue (on some compilers). Try: A<T> & foo (X p) { ... } Regards, Larry -- Anti-spam address, change each 'X' to '.' to reply directly.
[Prev in Thread] | Current Thread | [Next in Thread] |