Forward referencing templates..

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Oct 26 16:59:58 PDT 2006


James Dean Palmer wrote:
> Bradley Smith wrote:
>> James Dean Palmer wrote:
>>
>>> Sure, but remove the template aspect and consider the classes - we 
>>> have no trouble representing classes with infinitely recursive 
>>> relationships.  class Bob can point to an object of type Alice and 
>>> Alice can point to an object of type Bob.  I'd like to be able to do 
>>> the same thing with templatized classes.
>>
>> That would be like the following, which does compile.
>>
>  > ... snipped
> 
> Right, except I want Alice and Bob referenced when passed in as template 
> parameters.  :-)

D uses name mangling, and the mangled typenames of template parameters 
are included in the mangled name of the instantiated template type. 
Since if name A (strictly) includes name B and name B (strictly) 
includes name A then names A and B can't exist as finite strings, that 
makes it impossible to mangle A and B and thus to compile any code that 
uses them.

It could theoretically work if you use typedefs instead of aliases, 
since typedefs mangled names don't depend on the referenced type.
Currently also gives an error though:
test.d(19): typedef test.face3D circular definition

(the original code gives this error:
test.d(18): forward reference to 'face!(surface3D,edge3D)'
)



More information about the Digitalmars-d mailing list