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: A problems with templates


Topi Maenpaa wrote:
> 
> Hi,
> 
...
> the classical copy constructor - assignment operator pair (i.e. no
> templates). (Actually, to demonstrate the problem, only the copy
> constructor is needed.) For some reason, the template copy constructor
> (or any other constructor) is not called before "result" is deleted in
> Test:foo(void). 
...

You do need the non-template copy ctor if the implicitly generated isn't
good enough (as in your case):

From 12.8, p2:

A non-template constructor for class X is a copy constructor if its
first parameter is of type X&, const X&, volatile X& or const volatile
X&, and either there are no other parameters or else all other
parameters have default arguments (dcl.fct.default).* 

    [Footnote: Because a template constructor is never a copy
     constructor, the presence of such a template does not suppress
     the implicit declaration of a copy constructor. Template
     constructors participate in overload resolution with other
     constructors, including copy constructors, and a template
     constructor may be used to copy an object if it provides
     a better match than other constructors. --- end foonote]

Regards
Martin

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