Not able to load classes defined in archive file in Mac OSX using Object.factory

Aditya anlal at hotmail.com
Fri Nov 16 14:24:10 UTC 2018


Hello !

I am trying to work out "The D programming Language" chapter 1.6 
problem on Interfaces and Classes.

folder
./stats.d    (takes argument "Min/Max" on command line and loads 
them)
./ss/Stat.d  (defines interface named 'Stat')
./ss/Min.d   (defines class named 'Min' that implements Stat)

$ dmd -lib -g ss/*.d -of=ss.a
$ dmd -g stats.d ss.a
$ echo 3 5 1.3 4 10 4.5 1 5 | stats Min
object.Exception at stats.d(19): Invalid statistics function: Min

Code for stats.d -

import std.exception, std.stdio;
import ss.Stat;  // works !!

void main(string[] args){
	Stat[] stats;

	foreach (arg; args[1 .. $]) {

		// Doesn't work
		// string path = "stats." ~ arg ~ "." ~ arg;
		// string path = "stats." ~ arg;
		// string path = "stats.ss." ~ arg;
		// string path = "stats.ss." ~ arg ~ "." ~ arg;
		// string path = "ss." ~ arg;
		// string path = "ss." ~ arg ~ "." ~ arg;
		// string path = arg ~ "." ~ arg;
		// string path = arg;
		// string path = "stats.ss." ~ arg ~ "." ~ arg;

                  string path = arg;

		auto newStat = cast(Stat) Object.factory(path);
		enforce(newStat, "Invalid statistics function: " ~ path);
		stats ~= newStat;
	}
}

What is the path for Min class defined in Min.d inside ./ss 
folder that is compiled into ss.a ?

Thanks
Aditya



More information about the Digitalmars-d-learn mailing list