Boost logo

Boost :

From: James Curran/MVP (JamesCurran_at_[hidden])
Date: 1999-08-21 03:54:27


From: Reid Sweatman <reids_at_[hidden]>

>class foo
>{
>public:
> foo(value_type& T = nValue,bool initialise = false)
>{ if(initialize) Initialize(T); }
>};

Am I missing something? I don't see that working as expected...
Consider the simplified:

class foo
{
        int n;
public:
        foo(int N = 5,bool initialise = false)
{ if(initialize) n = N; }
};

Now, Case #1
Written: Foo X;
Effective: foo X(5,false);
Effect: X.n is not initialized.

Case #2
Written: foo X(7)
Effective: foo X(7, false);
Effect: X.n is not initialized.

Case #3
Written: foo X(7, true);
Effective: same
Effect: X.n is initialized to 7.

Case #4
Written: foo X(, true);
Effective: foo X(5, true); // almost....
Effect: X.n would be initialized to 5, if it weren't a syntax error.

        So, it would seem, that the only place where the default for the
second-to-last parameter could be used it, is an error. Furthermore, the
effect of case #2 is counter-intuitive.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk