poniedziałek, 23 marca 2009

Re: more constraints

I complained about C++'s lack of possibility to make some class members read-only on certain level of access protection (public, protected). Well, it is possible with references, but is just solution at syntax level - it needs additional storage, require two separate entities and proper initialization:

class Class {
public:
Class() : val(_val) {}

const int& val; // const ref

void set_val(int newval) {_val = newval;}

private:
int _val; // value
};
I don't like this code...

Brak komentarzy: