Read-only data members

Read-only data members

One means of achieving this (proxies are another, properties are a third) is by providing a public data member which is a const reference to an actual (non-const) private data member:


class ArrayDemo
{
private:
int myCount;


public:
const int& count;


ArrayDemo(void)
: myCount(0)
, count(myCount)
{}
};

你可能感兴趣的:(properties,Class)