digitalmars.D.bugs - self referencing Templated class bug (DMD 0.88)
- Mike Wynn (31/31) May 08 2004 I was writing a templated class with a "copy constructor" the
- J Anderson (25/57) May 08 2004 You need to add a . in front of inner references to the outer class.
I was writing a templated class with a "copy constructor" the templated code compiles without error, but any atempt to use it causes the error 'template instance Foo!(int) Foo is not a template declaration' (no line numbers, or hints to why) finally tracked this to the constructor, or any other method that tries to use the typeof(this) ... `typeof(this) getVal() { return this; }` will not work either static reference to `this` (obviously) ------------------------------------------------------------- // work around solution if just a copy constructor is needed class Base(T) { } class Derv(T) : Base!(T) { this( Base!(T) from ) { }; // Derv!(T) getVal() { return this; } // this will not work either } // desired class class Foo(T) { public: this( Foo!(T) from ) { } } alias Derv!(int) bi; alias Foo!(int) fi; // coment this out and the file compiles o.k. int main( char[][] args ) { return 0; } /// /// template instance Foo!(int) Foo is not a template declaration ///
May 08 2004
Mike Wynn wrote:I was writing a templated class with a "copy constructor" the templated code compiles without error, but any atempt to use it causes the error 'template instance Foo!(int) Foo is not a template declaration' (no line numbers, or hints to why) finally tracked this to the constructor, or any other method that tries to use the typeof(this) ... `typeof(this) getVal() { return this; }` will not work either static reference to `this` (obviously) ------------------------------------------------------------- // work around solution if just a copy constructor is needed class Base(T) { } class Derv(T) : Base!(T) { this( Base!(T) from ) { }; // Derv!(T) getVal() { return this; } // this will not work either } // desired class class Foo(T) { public: this( Foo!(T) from ) { } } alias Derv!(int) bi; alias Foo!(int) fi; // coment this out and the file compiles o.k. int main( char[][] args ) { return 0; } /// /// template instance Foo!(int) Foo is not a template declaration ///You need to add a . in front of inner references to the outer class. ie: class Base(T) {} class Derv(T) : Base!(T) { this( Base!(T) from ) { }; .Derv!(T) getVal() { return this; } // this will not work either } // desired class class Foo(T) { public: this( .Foo!(T) from ) { } } alias Derv!(int) bi; alias Foo!(int) fi; // coment this out and the file compiles o.k. int main( char[][] args ) { return 0; } -- -Anderson: http://badmama.com.au/~anderson/
May 08 2004
On Sat, 08 May 2004 19:26:00 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Mike Wynn wrote:Cheers for that, it all works now. Walter, is this the expected D behaviour or just a work around ? Mike.// desired class class Foo(T) { public: this( Foo!(T) from ) { } } alias Foo!(int) fi; // coment this out and the file compiles o.k. int main( char[][] args ) { return 0; } /// template instance Foo!(int) Foo is not a template declarationYou need to add a . in front of inner references to the outer class. ie: // desired class class Foo(T) { public: this( .Foo!(T) from ) { } } alias Foo!(int) fi; // coment this out and the file compiles o.k. int main( char[][] args ) { return 0; }
May 08 2004
"Mike Wynn" <one_mad_alien hotmail.com> wrote in message news:44sp90puq8h5k27pjbr02slduqm6abq4v1 4ax.com...Walter, is this the expected D behaviour or just a work around ?It's expected behavior. A class template declares a symbol for the template itself, and a symbol for each of the classes generated from it. The generated class names are within the scope of the template symbol. So, to get the class name, use Foo. To get the template name, you'll have to step outside the scope with .Foo.
May 25 2004