Topic: Template Constructors Broken in VC++ 6?
Author: "Sebastian Moleski" <sebmol@gmx.net>
Date: 2000/07/19 Raw View
It should call the first copy constructor. This is because a compiler should
always favor non-template before template functions.
Unfortunately, I do not where in the Standard this is said. But it's there,
I'm sure.
Regards,
Sebastian Moleski
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: fjh@cs.mu.OZ.AU (Fergus Henderson)
Date: 2000/07/20 Raw View
"Sebastian Moleski" <sebmol@gmx.net> writes:
>It should call the first copy constructor. This is because a compiler should
>always favor non-template before template functions.
>
>Unfortunately, I do not where in the Standard this is said. But it's there,
>I'm sure.
You're right: it's in 13.3.3 [over.match.best], paragraph 1.
| 13.3.3 - Best Viable Function [over.match.best]
...
| a viable function F1 is defined to be a
| better function than another viable function F2 if
...
| * F1 is a non-template function and F2 is a template function
| specialization, or,
...
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Googleplexation is NOT an option! <deja_pcm@my-deja.com>
Date: 2000/07/19 Raw View
I was using some code from the July/August C++ Report (p.39, listing 2)
that breaks under VC6. My question is; is VC6 broken or is the code
non-conformant? In essence, the code does something like this:
class X
{
public:
X() {}
X( const X& x )
{ cout << "Normal constructor\n"; }
template<typename T> X(const T& x)
{ cout << "Template constructor\n"; }
};
X t1;
X t2(t1);
Under VC6 it produces the error "error C2668: 'X::X' : ambiguous call
to overloaded function". MS states in the help for C2668 that this
error may be the result of improved ANSI conformance.
However, if you comment out the non-template copy constructor, the
compiler generates a default constructor so the template constructor
never gets called.
This is explained in Herb Sutter's book, Exceptional C++ where, on page
12, he quotes the C++ standard:
"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 provieds a
better match than other constructors."
So, if as stated above, "template constructors participate in overload
resolution with other constructors", what is the correct behaviour in
this circumstance??
Thanks,
- Peter.
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]