by clappski · 4y ago · 0 comments
Typically immutability in C++ is at the interface scope rather than structural, e.g. prefer this
struct MyType {
int x_;
MyType( int x ) : x_( x ) {}
};
void do_the_thing( const MyType& mt ); // mt.x_ = 1; doesn't compile, mt is const
over this struct MyType {
const int x_;
MyType( int x ) : x_( x ) {}
};
void do_the_thing( MyType mt ); // mt.x_ = 1; doesn't compile, x_ is constNo comments yet.