www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - self referencing Templated class bug (DMD 0.88)

reply Mike Wynn <one_mad_alien hotmail.com> writes:
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
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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
parent reply Mike Wynn <one_mad_alien hotmail.com> writes:
On Sat, 08 May 2004 19:26:00 +0800, J Anderson
<REMOVEanderson badmama.com.au> wrote:

Mike Wynn wrote:
// 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 declaration
You 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; }
Cheers for that, it all works now. Walter, is this the expected D behaviour or just a work around ? Mike.
May 08 2004
parent "Walter" <newshound digitalmars.com> writes:
"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