A problems with templates
Martin Sebor
sebor@roguewave.com
Wed Nov 1 08:23:00 GMT 2000
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
More information about the Gcc-bugs
mailing list