www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - extern in templates/classes

Hiya, tried something yesterday, did a template like this:

template WinStart(alias userEntryPoint)
{
extern (Windows) WinMain(...)
{
..
results = userEntryPoint(...);
..
}
}

Which supposed to be used as a mixin, so I wouldn't have to manually write the
ugly WinMain start for all programs.

Needless to say, this didn't work out, because extern, for somewhat obvious
reasons, is ignored for templates (and, I think I tried it, for classes as
well). What I don't understand is why the compiler lets this through without
saying anything, and instead you get linking errors thrown at you.

Another thought was that maybe extern could be allowed for templates without
arguments? As they would appear exactly the same everywhere they are used, no
unique names are needed.

Any ideas how to do with the ugly WinMain? Or any comments on the rest?

/ Ola Frid
Aug 04 2004