Re: Templates and Copy Constructors. Again.

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 02/23/05


Date: Tue, 22 Feb 2005 21:34:08 -0500


"Matt Bitten" <mbitten73@yahoo.com> wrote...
> Now, what is it that is NOT a copy constructor, that has everyone so

Everyone? I'd probably refrained from speaking for *everyone*...

> confused? I read in the standard in 12.8 that a "template
> constructor" is not a copy constructor. However, a global search of
> the standard turns up no other use of the term "template
> constructor". So what is a template constructor?
> [...]
> It is not clear to me that this is what the standard says, however.

class Foo {
public:
    template<class T> Foo(T const& t); // a template constructor
};

template<class T> class Bar {
public:
    template<class U> Bar(const Bar<U>&); // a template constructor
};

The point is that in neither case the template constructor implements
or works in lieu of the compiler-generated copy constructor, although
you might think that if in the first case "T" is Foo, then the c-tor
becomes
         Foo(Foo const& t);

and in the second case if U is the same as T, then it becomes

         Bar<T>(const Bar<T>&);

The Standard says that it's not going to happen. In both classes Foo
and Bar<T>, the copy constructor that has a very specific signature
is going to be provided and will take over for all copy-construction
needs.

Victor



Relevant Pages

  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.lang.c)
  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.programming)
  • Re: base/derived name unhiding but with ctors
    ... Well, one problem with that terminology is that, when reading those parts ... of the standard that refer to constructor "calls", ... including large parts of the standard. ... of the subject matter (which is the normal context sensitivity of words) ...
    (comp.lang.cpp)
  • RE: type initializers
    ... I'm no expert on the precise language of the CLI standard, ... without calling it's constructor. ... > - first access to any static field ... > - if I access an instance field, then I should have already the instance, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: initializing static class variables
    ... I don't believe that is correct, the standard says that hellois ... he crucial bit is Foowhich is value initialisation not default ... For value initialisation of Foo, x and y will be zero ... Either way the safe thing to do is to add a default constructor to Foo. ...
    (comp.lang.cpp)