www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What's wrong with this template?

reply BCS <BCS_member pathlink.com> writes:
this code:
vvvvvvvv
class T(int i)		// line 1
{
	T!(i) dup()
	{
		return new T!(i);
	}
}

void main()
{
	T!(1) t = new T!(1);
}
^^^^^^^^
gives these errors:

(3): template instance T is not a template declaration, it is a class
(3): T!(1) is used as a type
(5): template instance T is not a template declaration, it is a class
(5): T!(1) is used as a type
(11): T!(1) is used as a type

What an I doing wrong?
Jan 06 2006
parent reply Sean Kelly <sean f4.ca> writes:
BCS wrote:
 this code:
 vvvvvvvv
 class T(int i)        // line 1
 {
     T!(i) dup()
     {
         return new T!(i);
     }
 }
 
 void main()
 {
     T!(1) t = new T!(1);
 }

Try this: class T(int i) // line 1 { T dup() { return new T(); } } void main() { T!(1) t = new T!(1); }
Jan 06 2006
parent reply BCS <BCS_member pathlink.com> writes:
Thanks!!

Now, how about this:


class T(int i)        // line 1
{
     T!(i+1) inc()
     {
         return new T!(i+1)();
     }
}

void main()
{
     T!(1) t = new T!(1);
	T!(2).T t2 = t.inc();
}


can you use a template inside it's self?

Sean Kelly wrote:
 BCS wrote:
 
 this code:
 vvvvvvvv
 class T(int i)        // line 1
 {
     T!(i) dup()
     {
         return new T!(i);
     }
 }

 void main()
 {
     T!(1) t = new T!(1);
 }

Try this: class T(int i) // line 1 { T dup() { return new T(); } } void main() { T!(1) t = new T!(1); }

Jan 06 2006
parent reply Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
BCS wrote:
 Thanks!!
 
 Now, how about this:
 
 
 class T(int i)        // line 1
 {
     T!(i+1) inc()

Try .T!(i+1)
Jan 06 2006
parent BCS <BCS_member pathlink.com> writes:
Ivan Senji wrote:
 BCS wrote:
 
 Thanks!!

 Now, how about this:


 class T(int i)        // line 1
 {
     T!(i+1) inc()

Try .T!(i+1)

BINGO, that's just what I needed!
Jan 06 2006