template argument required

P

Patrick Rammelt

Hi

After upgrading my compiler (gcc-3.3.3 to gcc-4.0.0) I stumbled over an
error that I do not understand. Maybe it is a compiler bug, but maybe I
can get some new insights from this. Here is a small example:

------------------------------------------------------------------
template <class T>
class A {
public:

A (void) {}

template <class X>
A<T>& foo1 (X p) {
// ...
return(*this);
}

template <class X>
class A<T>& foo2 (X p) { // differns from foo1 only by "class"
// ...
return(*this);
}

template <class X>
A& foo3 (X p) {
// ...
return(*this);
}

template <class X>
class A& foo4 (X p) { // differns from foo3 only by "class"
// ...
return(*this);
}

};
----------------------------------------------------------------

gcc-3.3.3 accepts all foos. gcc-4.0.0 (and gcc-3.4.1) accepts all foos
but foo4 (notice: it differs from foo3 only by the keyword "class")[1].
In my understanding they are all identical. If I am wrong, could someone
please explain to me what the difference is?

Thanks and ciao,
Patrick

[1] The error message is "template argument required" and
points to where foo4 is called, not to the member-function iself.
 
V

Victor Bazarov

Patrick said:
After upgrading my compiler (gcc-3.3.3 to gcc-4.0.0) I stumbled over an
error that I do not understand. Maybe it is a compiler bug, but maybe I
can get some new insights from this. Here is a small example:

------------------------------------------------------------------
template <class T>
class A {
public:
[...]
template <class X>
class A& foo4 (X p) { // differns from foo3 only by "class"

Maybe the compiler thinks, hey, 'A' is not a class here. It's a template.
You're telling me that 'A' is a class. Then I will think it's not the 'A'
I am currently processing, since you picked to qualify it...

Maybe not. Comeau accepts it fine.
// ...
return(*this);
}

};
----------------------------------------------------------------

gcc-3.3.3 accepts all foos. gcc-4.0.0 (and gcc-3.4.1) accepts all foos
but foo4 (notice: it differs from foo3 only by the keyword "class")[1].
In my understanding they are all identical. If I am wrong, could someone
please explain to me what the difference is?

Thanks and ciao,
Patrick

[1] The error message is "template argument required" and
points to where foo4 is called, not to the member-function iself.

How and when they point out the errors is not specified in the Standard.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top