Is there a keyword to access the base class

Gary Willoughby dev at kalekold.net
Tue Jun 18 15:43:03 PDT 2013


I iterated on Ali's solution with more OOP to demonstrate 
features you may find interesting.

import std.stdio;

interface IBar
{
	@property int val();
}

class Bar : IBar
{
	protected int _val;

	@property int val()
	{
		return this._val;
	}
}

class Foo : Bar
{
	this()
	{
		this._val = 10;
	}
}
class Foos : Bar
{
	string str = "some more memory";

	this()
	{
		this._val = 20;
	}
}

void main()
{
	IBar[] bars; // <--- collection of objects conforming to your 
interface.
	
	bars ~= new Foo();
	bars ~= new Foos();
	
	foreach(IBar b; bars)
	{
		writeln(b.val);
	}
}


More information about the Digitalmars-d-learn mailing list