Idea to ease tail-const class reference woes
Simen Kjaeraas
simen.kjaras at gmail.com
Sun Mar 23 08:06:09 PDT 2008
On Sat, 22 Mar 2008 00:08:55 +0100, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> "Janice Caron" wrote
>> Oops. Typo. Let's try that again...
>>
>> Sounds more work than
>>
>> import std.typecons;
>> Rebindable!(C) myClass = new C;
>>
>> which is planned for the future. (See D2.012 change log)
>
> One further question on this...
>
> If I have:
>
> class C
> {
> void foo() {};
> }
>
> Rebindable!(const(C)) myC = new C;
>
> myC.foo();
>
> Is the plan for this to compile (I know it doesn't today)? If not, then
> this
> is not an acceptable solution.
>
> -Steve
Why should that compile? It clearly says that myC is const, and hence
non-const methods should not be callable on it.
Had it been:
class C
{
const void constFunc() {}
void nonConstFunc() {}
}
Rebindable!(const(C)) myC = new C;
myC.constFunc(); // should work, both myC and constFunc are const.
myC.nonConstFunc(); // should not work, might change myC's internal state.
--Simen
More information about the Digitalmars-d
mailing list