Indeed, looks ok in C++:
struct Foo {
const int x = 0;
int y = 0;
};
struct Bar {
const int x = 0;
int y = 0;
const Foo foo1 = Foo();
Foo foo2 = Foo();
};
void test() {
const Foo foo1 = Foo();
Foo foo2 = Foo();
const Bar bar1 = Bar();
Bar bar2 = Bar();
foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
foo1.y = 1; // ❌ Cannot assign to variable 'foo1' with const-qualified type 'const Foo'
foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
foo2.y = 1;
bar1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar1.y = 1; // ❌ Cannot assign to variable 'bar1' with const-qualified type 'const Bar'
bar1.foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar1.foo1.y = 1; // ❌ Cannot assign to non-static data member 'foo1' with const-qualified type 'const Foo'
bar1.foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar1.foo2.y = 1; // ❌ Cannot assign to variable 'bar1' with const-qualified type 'const Bar'
bar2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar2.y = 1;
bar2.foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar2.foo1.y = 1; // ❌ Cannot assign to non-static data member 'foo1' with const-qualified type 'const Foo'
bar2.foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
bar2.foo2.y = 1;
}
We can still love it even if it's not unique!