Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2004-10-22 10:34:45


Hi boost users,

A friend of mine wants to expose properties in his classes in the form
properties exist in other languages such as Delphi or VB or C#. I don't
agree with the idea since get and set methods are just fine for me but I
thought I would send this question out and see if any of you have a
recommendation. The idea would be the following:

class CButton
{
public:

    void SetColor(const int & nColor) { m_nColor = nColor; }
    const int & GetColor() const { return m_nColor; }

private:
    int m_nColor;
};

So of course we can set and retrieve the color of a CButton instance using
the get and set methods in the way:

CButton button;
button.SetColor(5);
int nColor = button.GetColor();

However what my friend wants to do is to expose methods so we can do:

button.color = 5;
int nColor = button.color;

...and the get and set method would be called internally. He already has a
solution for this problem using a template class property<TClass, TType>
that overrides operator= and operator value type, and then at runtime he
binds the get and set methods to the property object. However, one of the
things he would like to do is to not have to pass the class name to property
and/or not have to bind the get and set methods at runtime to the property.

I guess the functionality he wants is like the property keyword in VC++.
Unfortunately this is a Microsoft only extension.

Any ideas? Suggestions?

Thanks

-delfin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net