D2.0 const this methods
Daniel Keep
daniel.keep.lists at gmail.com
Mon Jun 18 01:22:25 PDT 2007
This seems to work:
class Foo
{
int x;
const(Foo) getThis()
{
x = 42;
return cast(const)this;
}
}
Remember that "const Foo" is actually "const const(Foo)": a *constant
reference* to a constant Foo. What you want is a plain old constant
Foo: const(Foo).
Your example is bad because "const int" by itself only really makes
sense as a declaration, not a return type: you're returning a const(int)
which doesn't do anything.
Does that help?
-- Daniel
More information about the Digitalmars-d
mailing list