A tutorial on D templates: updates

bls bizprac at orange.fr
Mon Jan 30 14:00:35 PST 2012


On 01/30/2012 01:14 PM, bls wrote:
> Hi Philippe,

slightly better ..
class PersonStack
{
	private string name;
	private int age;
	
	// Our Mixins
	mixin MIStack;
	mixin MIPublisher;
		
	this()
	{
		// Register some subscribers (MIPublisher register function)
		// I have used free functions to show the useful toDelegate()
		register( toDelegate(&DrawPersonBarChart) ); 	
		register( toDelegate(&DrawPersonPieChart) ); 	
	}
	
	// Push
	void add(string name, int age)
	{
		auto p = new PersonStack();
		p.name = name;
		p.age = age;
		// Add Person (MIStack push function.)
		push(p);
		
		// Notify all subscribers		
		notify("Push");
			
	}
	void remove()
	{
		auto el = pop();
		notify("Pop " ~ el.name );
	}
}


More information about the Digitalmars-d-announce mailing list