This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: A problems with templates
- To: Topi Maenpaa <topiolli at ees2 dot oulu dot fi>
- Subject: Re: A problems with templates
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Wed, 01 Nov 2000 09:28:08 -0700
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: Rogue Wave Software, Inc.
- References: <39FFCFDB.9E0CF5FC@ee.oulu.fi>
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