template forward reference (important)

BCS ao at pathlink.com
Tue Jul 31 12:23:13 PDT 2007


Reply to C. Dunn,

> I was really hoping to see a response to this.  It's going to prevent
> me from using "D" at all.

I think that there are no blocking problems with this, if you rearrange stuff 
enough it works (I can't prove this but I haven't ever failed to make things 
work)

> Because of forward declarations, templates are more flexible in C++. 

As to c++ being more flexible than D, some things might take a bit of work 
(like what you are looking at), but in all but the most trivial cases c++ 
can't even hold a candle to D.

> This problem really needs to be addressed.

votes ++; // it is a problem, I agree





OTOH this runs, or am I changing something?

dmd 1.017 win32

<code name="ModA.d">
|import ModA;
|
|class Foo(T)
|{
|	int bar()
|	{
|		return A.hi();
|	}
|};
</code>

<code name="ModA.d">
|import ModFoo;
|import std.stdio;
|
|class A{
|	static int hi()
|	{
|		writef("boo");
|		return 0;
|	}
|
|	Foo!(char) x;
|};
|
|void main()
|{
|	A a = new A;
|	a.x = new typeof(a.x);
|	a.x.bar();
|}
</code>





More information about the Digitalmars-d mailing list