help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: template argument required


From: Larry I Smith
Subject: Re: template argument required
Date: Sun, 15 May 2005 16:26:07 GMT
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20050414

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?

Thanks and ciao,
Patrick

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);
   }

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]