February 09, 2003 how do I use template( char T : 'x', P ) ? | ||||
---|---|---|---|---|
| ||||
I found that extern( foo ) instance .... did not migrate the linkage to the template so not wanting to use an enum, first I tried template( char[] T : "Windows", R ) but that does not work :( tet5.d(2): template base(char[] : "W",R) integral type expected for value-parame ter, not char[] then I tried this template base( char T : 'W', R ) { extern (Windows) alias R (*fp)(); fp func; } template base( char T : 'C', R ) { extern (C) alias R (*fp)(); fp func; } const char WWWW = 'W'; instance base( WWWW, int ) other; instance base( 'W', int ) te; extern( Windows ) alias int (*wfp)(); extern( Windows ) alias te.fp awfp; int myd_func(){ return 2; } int main( char[][] args ) { wfp wfunc; awfp awfunc; awfunc = &myd_func; te.func = &myd_func; wfunc = &myd_func; // only windows fp return 0; } the templates compile .... BUT there is no way to create an instance on them instance base("W",int) does not match any template declaration with both 'W' or a const Mike. |
March 12, 2003 Re: how do I use template( char T : 'x', P ) ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:b245qp$1eud$1@digitaldaemon.com... > I found that extern( foo ) instance .... did not migrate the linkage to the > template Right. It compiles the template in the context it was defined in, not the context of the instance. > so not wanting to use an enum, first I tried template( char[] T : "Windows", > R ) > but that does not work :( > tet5.d(2): template base(char[] : "W",R) integral type expected for > value-parame > ter, not char[] Right, only integral values supported for value parameters. > then I tried this > > template base( char T : 'W', R ) > { > extern (Windows) alias R (*fp)(); > fp func; > } > > template base( char T : 'C', R ) > { > extern (C) alias R (*fp)(); > fp func; > } > > const char WWWW = 'W'; > instance base( WWWW, int ) other; > instance base( 'W', int ) te; > extern( Windows ) alias int (*wfp)(); > extern( Windows ) alias te.fp awfp; > > int myd_func(){ return 2; } > > int main( char[][] args ) > { > wfp wfunc; > awfp awfunc; > awfunc = &myd_func; > te.func = &myd_func; > wfunc = &myd_func; // only windows fp > return 0; > } > > the templates compile .... BUT > there is no way to create an instance on them > > instance base("W",int) does not match any template declaration > > with both 'W' or a const I'll log that as a compiler bug. |
Copyright © 1999-2021 by the D Language Foundation