Topic: How to be a friend (with templates)
Author: geert@cs.ruu.nl (Geert-Jan Giezeman)
Date: 1997/12/24 Raw View
I want to make a function template a friend of a templated class.
According to the September 1996 draft standard, section 14.5.3,
I did it one way (see below), but when I did it this way, the egcs compiler
(which is the compiler closest to the standard that I have access to)
complains that I have to add <> after the function name.
Could some kind soul explain to me what is the case here:
A) egcs is wrong.
B) the standard has changed in this respect since the draft.
C) the example in the standard was wrong as it was.
D) something else.
As I use this in code that works under as much compilers as possible, I want
to know what is the right way of doing it, so I can work around the
bugs, not around the features.
Please reply with email (as well as posting), as I won't read this forum
the next two weeks.
--- extended example from 14.5.3.1 ---
template <class T>
class task;
template <class T>
void preempt(task<T> *t);
template <class T>
class task {
void priv() const {};
public:
friend void preempt(task<T> *t); // according to draft
// friend void preempt <> (task<T> *t); // according to egcs
};
template <class T>
void preempt(task<T> *t)
{
t->priv();
}
main()
{
task<double> ad;
preempt(&ad);
}
--
Geert-Jan Giezeman, Dept. of Computer Science, Utrecht University
URL: http://www.cs.ruu.nl/staff/geert.html Email: geert@cs.ruu.nl
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]