Templates and operators

Carlos Saona-Vázquez csaona@netscape.net
Fri Apr 28 10:21:00 GMT 2000


The code below worked with g++ 2.8.1 and 2.91.66. But version 2.95.2
does not like it. I've tried in Irix 6.5 and Solaris 5.7.


---------The code

template<unsigned int n,class R> class mm;
template<unsigned int n,class R> mm<n,R> operator*(const R a,const mm<n,R>&
b);

template<unsigned int n,class R>
class mm
{
private:
  R x[n];
public:
  mm() {}
  mm operator*(const R a) {}
  friend mm operator*<> (const R a,const mm<n,R>& b);
};

template<unsigned int n,class R>
inline mm<n,R> operator*(const R a,const mm<n,R>& b)
{
  return mm<n,R>();
}

main()
{
  mm<3,int> kk;
}
---------And the error:
> g++ mm.cc
mm.cc: In instantiation of `mm<3,int>':
mm.cc:29:   instantiated from here
mm.cc:18: invalid use of undefined type `class mm<3,int>'
mm.cc:19: forward declaration of `class mm<3,int>'
mm.cc:18: confused by earlier errors, bailing out

--------------
 I think it gets confused with the member and non-member operators,
because it works alright if you change the name of either.

It also works if you made both operators (right and left) non-member
friends. But I think that the code above should work also.

Carlos

____________________________________________________________________
Get your own FREE, personal Netscape WebMail account today at http://webmail.netscape.com .


More information about the Gcc-bugs mailing list