Suppose I have
class A final {
int& ir;
public:
A(int& x) : ir(x) { }
void set(int y) { ir = y; } // non-const method!
int get() const { return ir; }
};
and
const int i;
Obviously I can't have
A a(i);
since that would breaks constness. But I also cannot have
const A a(i);
despite the fact that this will not break constness de-facto. C++ doesn't support "const-only" ctors, e.g. in this case one which would take a const int&
. Is there a way to get const A a
wrapping a reference to i
- other than
A a(const_cast<int &>(i))
?