Question on Octal

Michael pongad at gmail.com
Wed Aug 15 10:49:53 PDT 2012


Hi all,
   I have just read Walter's article about octals on Dr. Dobb's. 
As a newbie, I tried to create one myself.

template octal(int n) {
	int toOct(int x) {...}
	
	enum octal = toOct(n);
}

void main() {
	import std.stdio : writeln;
	writeln(octal!10);
}

I have two questions about this.
1) The specification is clear that the if the template has only 
one member and the member has the same name with the template's, 
the member is implicitly referred to in the instantiation. The 
template octal has two members, so the program should not really 
be compiling, and yet it does. Is this a compiler bug?
2) I chose the declare the inner "octal" as an enum following 
Walter's example. But why enum? What would be different if it 
were auto, immutable, or static?

Thanks guys!
Michael


More information about the Digitalmars-d-learn mailing list