const method and return type

Ali Çehreli acehreli at yahoo.com
Sat Dec 14 14:38:24 PST 2013


On 12/13/2013 04:24 PM, Andrea Fontana wrote:

 > Just another thought. If we have:
 >
 > class B;
 > struct C;
 >
 > class A
 > {
 >     void method() const { ... }
 >     B another_class;
 >     C a_struct;
 > }
 >
 > B is just a reference to a object, so method() should not reassign it.
 > The reference should be const, not the object itself. method() should be
 > able to call mutable another_class methods.

However, according to how D sees constness, mutating another_class 
through its non-const methods would mutate the state of A as well.

Ali



More information about the Digitalmars-d-learn mailing list