Boost logo

Boost :

From: Geurt Vos (G.Vos_at_[hidden])
Date: 2002-02-14 03:37:48


> IMHO, the ONLY advantage of a 'property' in comparison with
> the good old:
>
> int const& foo() const { return m_foo ; }
> int & foo() { return m_foo ; }
> int m_foo ;
>
> is that the user don't have to write the extra '()'.
>

This isn't exactly the same. That is, foo() returns
a reference to the internal object, which means one
can assign directly to it. This is exactly what I
don't want. foo() = 0 shouldn't get past the compiler.
Instead it should be something like:

    int foo() const;
    void foo(int);

then stuff like:

    int i = a.foo();
    a.foo(100);

is still nice, but it can get ugly:

    a.foo(a.foo() * 20);
    a.foo(a.foo() + b.foo());

whereas with properties you'd write:

    a.foo *= 20;
    a.foo += b.foo;

Geurt


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