Friends of template classes.
Jacek Generowicz
jmg@ecs.soton.ac.uk
Mon Dec 13 08:25:00 GMT 1999
Hi,
On page 854 of the C++ Programming language Edition 3, Stroustrup
implies that friends of template classes can be declared thus:
template<class T> class Thing {
friend return_type fn_name( args );
.
.
.
}
Whenever I try to compile something of this sort with g++ I get errors
of the following general type
friend declaration `return_type fn_name( args )'
declares a non-template function
(if this is not what you intended, make sure
the function template has already been declared,
and add <> after the function name here)
Following this suggestion I tried
template<class T> class Thing {
friend return_type fn_name<> ( args );
.
.
.
}
which works fine.
However, I am now sharing development with people using different
compilers (Microsoft Visual C++): the second version of the code does
not work for them while the first one does.
Is this a non-standard feature of g++ or is my understanding of C++
failing me ? Are there any ways to get around the apparent
incompatibility ?
Thanks,
Jacek
More information about the Gcc
mailing list