Topic: push_back<Args> and explicit constructors
Author: mitsukai89@gmail.com
Date: Wed, 7 Nov 2007 10:14:48 CST Raw View
On 2 nov, 16:34, Magnus F <ma...@lysator.liu.se> wrote:
> If I read n2461 correctly then the following code:
>
> struct Foo {
> explicit Foo(int) { }
>
> };
>
> int main()
> {
> std::vector<Foo> fv;
> fv.push_back(1);
>
> }
>
> is valid and would insert a Foo(1) instance in fv.
>
> This would be a change from 14882:2003 where it was a compile error.
> Is this an intended change or not?
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]
The function calls an implicit conversion not an explicit conversion,
so the constructor signature does not match
---
[ 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://www.comeaucomputing.com/csc/faq.html ]
Author: Magnus F <magfr@lysator.liu.se>
Date: Fri, 2 Nov 2007 09:34:25 CST Raw View
If I read n2461 correctly then the following code:
struct Foo {
explicit Foo(int) { }
};
int main()
{
std::vector<Foo> fv;
fv.push_back(1);
}
is valid and would insert a Foo(1) instance in fv.
This would be a change from 14882:2003 where it was a compile error.
Is this an intended change or not?
---
[ 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://www.comeaucomputing.com/csc/faq.html ]