Pointer to a generic class or structure

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
 
C

Carl Daniel [VC++ MVP]

Dodo 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()

You should post this question to

microsoft.public.dotnet.languages.csharp. This newsgroup is for C++.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top