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]

Re: member-template bug in egcs



>>>>> "Michael" == Michael A Benzinger <mbenz@sabre.com> writes:
> At 02:18 AM 11/21/97 -0200, Alexandre Oliva wrote:
> >Michael A Benzinger writes:
> >
> >> In other words, you can construct a complex<T1> from a complex<T2> if and
> >> only if you can initialize a T1 by a T2.  That seems reasonable."
> >
> >It really does, but, unless I've missed some important part of the
> >standard, a specialization of a template class does not implicitly
> >gain priviledged access to another specialization of the same template
> >class.
> >
> "A class or a class template can have members that are themselves templates.
> For example:
> 
>   template<class Scalar> class complex {
> 	 Scalar re, im;
>   public:
> 	 template <class T>
> 	      complex(const complex<T>& c) : re(c.re), im(c.im) { }
> 	 // ...
> };
> 
> What Klaus is trying to do here is create a "template member FUNCTION".
> This is not a definition of a new template CLASS.  A template member
> function DOES have access to the private members of a template class.

Two things:
- The template member function has of course access to this->re and
  this->im. complex<T> however is a different type (CD2: 14.4
  [temp.type]) (thanks Alexandre for the hint). I have not found
  anything in the CD2 which would give this special access rights to
  a complex<T>, which is a different type.
  If I have missed something, please let me know.
- Another thing: the above member template is not a copy
  constructor. A copy constructor has to be non-template.

> You can also consult Scott Meyers' "Effective C++, Second Edition"
> for more information on this.

I'm curious: which item do you refer to?

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie II                           Tel: 0721 608 3485
Uni Karlsruhe
-------------------------------------------------------------------------


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