Does C++11 have C#-style properties?

In C++ you can write your own features.
Here is an example implementation of properties using unnamed classes. Wikipedia article

struct Foo
{
    class {
        int value;
        public:
            int & operator = (const int &i) { return value = i; }
            operator int () const { return value; }
    } alpha;

    class {
        float value;
        public:
            float & operator = (const float &f) { return value = f; }
            operator float () const { return value; }
    } bravo;
};

You can write your own getters & setters in place and if you want holder class member access you can extend this example code.

Leave a Comment