473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3650
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
6191
by: wogston | last post by:
A) template <typename scalar, int size> struct basevector { enum { size = size }; scalar v; }; B)
8
11367
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 f2(ANY, ANY) ANY f3(ANY, ANY, ANY)
2
2475
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. i would forget overriding it but i have to do it because its a coursework. here is a simple version of the class #include <iostream> #include <string> #include <vector>
4
1418
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 derived from B, while the template version should be called for all other argument types? #include <iostream> using namespace std;
14
2905
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&); template<typename T>
2
1412
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? Thanks,
2
1852
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: template<typename InputIterator> Foo(InputIterator i); Foo(const Bar & b);
12
2328
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 <iostream> using namespace std; template <class ClassB> class ClassA
8
2969
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
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.