On 01/02/2015 09:07 PM, ketmar via Digitalmars-d-learn wrote:

> structure instance with const fields can be initialized only once, upon
> creation. so did `Test myTest1;` -- you initialized `myTest1` with
> default values. you can't reinitialize it later.
>
> in C++ constness on member doesn't impose such restrictions.

C++ has the same restriction: const members make objects unassignable:

struct S
{
    const int i;

    S()
        : i()
    {}
};

int main()
{
    S a;
    S b;
    a = b;
}

error: non-static const member ‘const int S::i’, can't use default assignment operator

Ali

Reply via email to