const and immutable member variables in classes
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 2 14:48:03 PST 2016
const and immutable members make structs non-assignable:
struct S {
const int c; // Makes S non-assignable
immutable int i; // Makes S non-assignable
}
void main() {
auto a = S();
auto b = S();
a = b; // Compilation ERROR
}
(That is the same issue in C++.)
That's why I've been avoiding them altogether. However, considering that
there is no default-assignment for classes, there is no problem with
using const or immutable members with classes, right?
Ali
More information about the Digitalmars-d-learn
mailing list