Pointer to a generic Class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Dodo Cibelli said:
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*) .....
}
}

I do not believe this is possible.

As to why? Well, pointer work requires knowledge of the size of the
datatype, so I'd guess no one felt it was something that anyone needed. But
I don't know for sure.
 
Back
Top