This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

template bug



The preprocessed code below generates the following compiler error:

foo.C: In instantiation of `foo<double>':
foo.C:45:   instantiated from here
foo.C:16: invalid use of undefined type `class foo<double>'
foo.C:23: forward declaration of `class foo<double>'

Here are the vitals:

g++ -v
Reading specs from /usr/local/lib/gcc-lib/mips-sgi-irix6.5/2.95.2/specs
gcc version 2.95.2 19991024 (release)

uname
IRIX mozart 6.5 10181059 IP32 mips

BUG DESCRIPTION:

   This is an example program written to demonstrate the bug.  The problem
occurs when operator*() is declared as both a friend and member.  No
problem occurs when operator*() is declared only as a friend or only as a
member. Comment out the member definition and declaration of operator*()
and everything works.

Thanks for any help.
JM

P.S. please cc me. I'm not on the list.
 
---------- BEGIN SOURCE ----------
# 1 "foo.C"

template <class EType>
class foo;

template <class EType>
foo<EType> operator*( const EType &, const foo<EType> & );

template <class EType>
class foo {

  public:

     foo( const EType v = 0 ) : Value( v ) {};
     virtual ~foo( ) {};

     friend foo<EType> operator* <> ( const EType &, const foo<EType> & );

     foo<EType> operator*( const EType & );

  private:

     EType Value;
};


 

template <class EType>
foo<EType> operator*( const EType & e, const foo<EType> & f )
{
   return foo<EType>( e * f.Value );
}


 

template <class EType>
foo<EType> foo<EType>::operator*( const EType & e )
{
   return foo<EType>( e * Value );
}

int main( )
{
   foo<double> f( 5.0 );
   return 0;
}

template <class EType>
class foo;

template <class EType>
foo<EType> operator*( const EType &, const foo<EType> & );

template <class EType>
class foo {

  public:

     foo( const EType v = 0 ) : Value( v ) {};
     virtual ~foo( ) {};

     friend foo<EType> operator* <> ( const EType &, const foo<EType> & );

     foo<EType> operator*( const EType & );

  private:

     EType Value;
};


// Friend Function operator* definition

template <class EType>
foo<EType> operator*( const EType & e, const foo<EType> & f )
{
   return foo<EType>( e * f.Value );
}


// Member Function operator * definition

template <class EType>
foo<EType> foo<EType>::operator*( const EType & e )
{
   return foo<EType>( e * Value );
}

int main( )
{
   foo<double> f( 5.0 );
   return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]