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 -- Email see: http://user.cs.tu-berlin.de/~rammelt/mail.gif _______________________________________________ Help-gplusplus mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gplusplus
