On Thursday, October 11, 2018 at 1:51:52 AM UTC-4, Öö Tiib wrote:
> On Thursday, 11 October 2018 01:01:07 UTC+3, Daniel wrote:
> >
> > class A
> > {
> > int n;
> > public:
> > A() = delete;
> > A(int n)
> > : n(n)
> > {
> > }
> > };
> >
> > template <class T>
> > class B
> > {
> > T t;
> > public:
> > B(T t = T())
> > : t(t)
> > {
> > }
> > };
> >
> > (1) B<A>(); // fails, as expected
>
> You mean by being most vexing parse?
>
No, this fails because the template argument supplied doesn't have a default
constructor, so T() isn't defined.
> > (2) B<A>(A(1)); // ?
> >
> > Is it for certain that the expression T() won't get evaluated in (2)?
>
> Yes.
Just want to be sure that no compiler would evaluate
the default parameter (and hence fail) if an actual parameter was passed.
Daniel