public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Template with friend methods problem
@ 2000-09-11  9:07 Christian Savard
  0 siblings, 0 replies; only message in thread
From: Christian Savard @ 2000-09-11  9:07 UTC (permalink / raw)
  To: gcc

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];
}
		

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-09-11  9:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-11  9:07 Template with friend methods problem Christian Savard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).