Boost logo

Boost :

From: Aaron Linnen (linnena_at_[hidden])
Date: 2002-05-13 11:58:20


Dragan Milenkovic wrote:

[snip]

> And now to get on with my nonsense... I wanted to create some
> utilities for get/set member functions. I was wondering why this has
> not found its place in the boost libraries.
>

[snip]

> I have considered something like this:
>
> class Foo {
> public:
> Member x;
>
> Foo() : x(this, &Foo::get_x, &Foo::set_x) {}
>
> private: // or protected
> int get_x(); // and have these virtual
> void set_x(int);
> };
>

[snip]

Borland's C++ Builder compiler has this feature, and it's handy. Their syntax:
class Foo {
public:
    __property TRect Bounds = {read = FBounds, write = SetBounds};
    __property int Width = {read=FWidth};
private:
    int FWidth;
    TRect FBounds;
    void SetBounds(TRect R);
}
You can use the variables directly (e.g. to read the FBounds above), or a function
(the SetBounds). If either read or write isn't specified, the property becomes
write only or read only. In the second example, Width becomes a read only access
to the FWidth private member.

Of course, Borland has the option of compiler extensions, while boost doesn't.
Aaron


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