Pointer to a generic class or structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dodo Cibelli

    #1

    Pointer to a generic class or structure

    Hello

    I'd like to write a Generic class that use a pointer to the generic structure.

    I can't do this
    unsafe public class PClass<S> where S : new()
    {
    public S* pData;

    public PClass( )
    {
    pData = (S*) .....
    }
    }

    Nor

    public class PClass<S> where S : new()
    {

    unsafe public void Pippo( )
    {
    S myS = new S();
    fixed (S* pSClass = &myS )
    {
    ..............
    }
    }
    }


    While I can do this having defined MyStruct

    unsafe public class PClass()
    {
    public void* pData;
    public MyStruct* pData2;

    public PClass( )
    {
    pData= (void*) .....
    pData2= (MyStruct*) .....
    }

    unsafe public void Pippo( )
    {
    float[] myS = new float[100];
    fixed (float* pSClass = &myS )
    {
    ..............
    }
    }

    }



    HOW COME THE GENERIC VERSION IS NOT ALLOWED ?
    I REALLY CAN'T FIGURE IT OUT.

    Many thanks
  • Carl Daniel [VC++ MVP]

    #2
    Re: Pointer to a generic class or structure

    Dodo Cibelli wrote:[color=blue]
    > Hello
    >
    > I'd like to write a Generic class that use a pointer to the generic
    > structure.
    >
    > I can't do this
    > unsafe public class PClass<S> where S : new()[/color]

    You should post this question to

    microsoft.publi c.dotnet.langua ges.csharp. This newsgroup is for C++.

    -cd


    Comment

    Working...