Gyro, object creation

  • Thread starter Thread starter Ole Andre Karlson
  • Start date Start date
O

Ole Andre Karlson

Hi

Im using the generic constructs provided by the Gyro
installation.
I want to create an object of a generic class parameter,
my code goes something like this:

class Node<T> where T : Node<T> {
....
T temp = new T(); <- Error
....
}

class City : Node<City> {
....
}

This isn't legal, is there anyway to work around this, so
I can create a T object?

thanks
Ole Andre Karlson
 
Ole Andre Karlson said:
Hi

Im using the generic constructs provided by the Gyro
installation.
I want to create an object of a generic class parameter,
my code goes something like this:

class Node<T> where T : Node<T> {

class Node<T> where T : Node<T>, new() {

I haven't tried this, but it should put a constraint on T, that it must have
a public default constructor.

Peter Stricker
 
Back
Top