Template with friend methods problem
Christian Savard
savardch@IRO.UMontreal.CA
Mon Sep 11 09:07:00 GMT 2000
Hi,
I can't get the following code to compile under Linux with gcc-2.95.2.
I've looked through the mailing-list archive and FAQ with no success.. Is this a
known bug? I'm pretty sure it's something I'm doing wrong.
I would appreciate any help or comments.
Thank you in advance
C.
Here's the error message I get:
../../Include/CGMath/Vec2.h: In instantiation of `cVec2<double>':
../../Include/LandGen/Hf.h:48: instantiated from here
../../Include/CGMath/Vec2.h:29: invalid use of undefined type `class
cVec2<double>'
../../Include/CGMath/Vec2.h:67: forward declaration of `class cVec2<double>'
And here's a small chunk of code from this class:
// Forward declaration for friends templates
template< class T >
class cVec2;
template< class T >
cVec2<T> operator*( const T &lOperand, const cVec2<T> &lVec );
template< class T >
cOStream& operator<<( cOStream &lStream, const cVec2<T> &lVec );
template< class T >
cIStream& operator>>( cIStream &lStream, cVec2<T> &lVec );
template< class T > class cVec2
{
friend cVec2<T> operator*<>( const T &lOperand, const cVec2<T> &lVec );
friend cOStream& operator<<<>( cOStream &lStream, const cVec2<T> &lVec );
friend cIStream& operator>><>( cIStream &lStream, cVec2<T> &lVec );
...
};
// Typedefs
typedef cVec2< int > cVec2i;
typedef cVec2< float > cVec2f;
typedef cVec2< double > cVec2d;
template< class T >
inline cVec2<T>
operator*
( const T & lOperand, const cVec2<T> &lVec )
{
return cVec2<T>( lVec.mData[0] * lOperand, lVec.mData.mData[1] * lOperand );
}
template< class T >
inline cOStream&
operator<<
( cOStream &lStream, const cVec2<T> &lVec )
{
return lStream << lVec.mData[0] << " " << lVec.mData[1];
}
template< class T >
inline cIStream&
operator>>
( cIStream &lStream, cVec2<T> &lVec )
{
return lStream >> lVec.mData[0] >> lVec.mData[1];
}
More information about the Gcc
mailing list