Topic: Template member functions
Author: leavens@cs.iastate.edu (Gary Leavens)
Date: 1995/08/08 Raw View
On page 14-2 in the 28 April 1995 draft of the C++ Standard,
an example is given of a template member function within a class.
I don't see how the grammar for member-specification (section 9.2 [class.mem])
permits this. I presume this is a mistake in the grammar
for member-specification?
Gary Leavens
--
229 Atanasoff Hall, Department of Computer Science
Iowa State Univ., Ames, Iowa 50011-1040 USA / leavens@cs.iastate.edu
phone: (515)294-1580 fax: (515)294-0258 ftp site: ftp.cs.iastate.edu
URL: http://www.cs.iastate.edu/~leavens/homepage.html
Author: amitp@owlnet.rice.edu (Amit Jayant Patel)
Date: 5 Sep 1994 18:58:32 GMT Raw View
In article <9424816.16085@mulga.cs.mu.oz.au>,
Fergus Henderson <fjh@munta.cs.mu.OZ.AU> wrote:
>jhgreen@ahab.eecs.nwu.edu (Jethro H. Greene) writes:
>
>>class Print {
>>public:
>> template <class T> void print(T arg1) cout << arg1.data << "\n";
>>};
[error messages deleted]
>
>Your code is correct - but your compiler is out-of-date.
>
>Originally member function templates were not allowed.
>The ANSI/ISO committee recently decided to allow them,
>but most compilers haven't implemented them yet.
This is good news! :) Are virtual member function templates allowed?
It sounds like non-virtual member function templates are not too hard,
but virtual ones could be troublesome.
- Amit
--
o
--/--
__\
<|> \
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 6 Sep 1994 09:06:24 GMT Raw View
amitp@owlnet.rice.edu (Amit Jayant Patel) writes:
>This is good news! :) Are virtual member function templates allowed?
No.
>It sounds like non-virtual member function templates are not too hard,
>but virtual ones could be troublesome.
You guessed it.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: dallison@bfsec.bt.co.uk (Dave Allison)
Date: Thu, 10 Jun 1993 08:51:54 GMT Raw View
*** If this is an FAQ, please ignore ***
If I have a template such as:
template <class T1, class T2>
class Fred {
joe(T1,T2) ;
} ;
I have to define the member function joe as:
template <class T1, class T2>
Fred<T1,T2>::joe(T1 a, T2 b) {}
But isn't this a little verbose. I mean, why do you have to put
the whole template parameter list after the template name (Fred)? A
class template name cannot be overloaded, so the compiler would know
which template was being referenced. Would the following not do?
(I know its illegal, but should it be?)
template <class T1, class T2>
Fred::joe(T1 a, T2 b) {}
or even:
template <class T1, class T2>
Fred<>::joe(T1 a, T2 b) {}
By insisting on the template parameter list it means that the compiler
has to verify that all the parameters are there and in the correct
order. It also means more typing for the programmer who is writing the
template.
Is the following wrong?
template <class T1, class T2>
Fred<T2,T1>::joe (T1 a, T2 b) {}
What about:
template <class T1, class T2>
Fred<T1,int>::joe (T1 a, T2 b) {}
It seems to me that the syntax of the language is over the
top at this point. Any comments?
[The reason I am interested in this is that I am writing a C++
compiler at the moment, and am currently getting frustrated.]
Dave Allison