template forward reference
Sean Kelly
sean at f4.ca
Tue Jul 31 14:43:27 PDT 2007
C. Dunn wrote:
> This works:
> <code>
> class Foo(T){
> int bar(){
> return A.hi();
> }
> };
>
> class A{
> static int hi(){
> return 0;
> }
>
> F!(char) x;
> };
> </code>
>
> But if I split these into 2 separate modules, where each module imports the other, then the module with class A does not compile:
> Error: forward reference to 'Foo!(char)'
> Error: F is used as a type
>
> If I make the template class a regular class, it compiles fine. I understand that cyclic template specializations could create problems, but I don't see why moving a template into a separate module fails. This works easily in C++ by just forward-declaring class A.
Right. And forward declarations are impossible in D because a type's
name includes the module in which it is declared.
> Why does this not work? Are there plans to support it in the future?
It looks like a compiler bug to me, though who knows when it will be
addressed.
Sean
More information about the Digitalmars-d
mailing list