Gyro, object creation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ole Andre Karlson

    #1

    Gyro, object creation

    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
  • Peter Stricker

    #2
    Re: Gyro, object creation

    "Ole Andre Karlson" <oleaka@ifi.uio .no> wrote in message
    news:0e9201c37d d4$6080d320$a10 1280a@phx.gbl.. .[color=blue]
    > 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> {[/color]

    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

    [color=blue]
    > ...
    > 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[/color]


    Comment

    Working...