*final* class member (D2)

Derek Parnell derek at nomail.afraid.org
Wed Feb 13 21:15:20 PST 2008


On Wed, 13 Feb 2008 10:59:26 -0500, Denton Cockburn wrote:

> How do I do this?  I'm trying to create a class member here that needs to
> be initialized in the constructor, but cannot be changed later.

The code below seems to work for me (DMD v2.008)

class A
{
   const real delegate() dg; // this is that function;

   this(const real delegate() dg) { this.dg = dg; }
}

class B
{
   real foo() { return 3.5; }
}

class C
{
   real foo() { return 4.5; }
}

void main()
{
   auto b = new B;
   auto a = new A(&b.foo);
   auto c = new C;
   a.dg = &c.foo; // correctly fails to compile.
}



-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
14/02/2008 4:13:59 PM


More information about the Digitalmars-d-learn mailing list