473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

template argument required

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.
--
Email see: http://user.cs.tu-berlin.de/~rammelt/mail.gif
Jul 23 '05 #1
1 3630
Patrick Rammelt wrote:
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
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: wogston | last post by:
A) template <typename scalar, int size> struct basevector { enum { size = size }; scalar v; }; B)
8
by: vpadial | last post by:
Hello, I want to build a library to help exporting c++ functions to a scripting languagge. The scripting language provides a function to register functions like: ANY f0() ANY f1(ANY) ANY...
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
4
by: Imre | last post by:
Why is the function template a better match for the call in the following code? And how could I write a version of F() that should be called if the argument is a pointer to a type that is...
14
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); ...
2
by: Siegfried Heintze | last post by:
I'm running on g++ v2.95 and 3.2. Why is it that the print functions work fine without any extra template parameters, but the SizeOfCod2 function requires that the bold code be uncommented? ...
2
by: Glenn G. Chappell | last post by:
I am trying to write two constructors for the same class. One takes an iterator and so is a template. The other takes a particular type by reference to const. class Foo { public:...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.