473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Pointer to a generic Class

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

Nov 17 '05 #1
1 1923

"Dodo Cibelli" <Do*********@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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.
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dodo Cibelli | last post by:
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( )
49
by: elmar | last post by:
Hi Clers, If I look at my ~200000 lines of C code programmed over the past 15 years, there is one annoying thing in this smart language, which somehow reduces the 'beauty' of the source code...
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
3
by: Frederick Gotham | last post by:
For objects, we have "void*" as the generic pointer type. For instance: enum ParamType { Int, Double }; void Func(void *const p,ParamType const pt) { switch (pt) { case Int: *(int*)p = 42;...
1
by: interX | last post by:
Hi I'm new in VC++ and have a question to generics. I have a generic class, which contains an array of the generic type. This array I can pin and then I would like to get an unmanaged pointer to...
13
by: arnuld | last post by:
i see the use of pointers, from K&R2 but what is the use of: 1. "pointer to pointer": char c; char** ppc; 2. pointer to function:
2
by: software | last post by:
Hello, I am a new bee to c++/cli, here's my question: I have a template version of a smart pointer class I can't use in my application because I need to use it in more than one assembly. I...
2
by: Nadeem Afroz | last post by:
Hello Folks!!!! i have one interesting question over here .......... Is it possible to create a generic pointer (generic pointer to member functions) which can point to all the member...
5
by: alan | last post by:
Hello world, I'm trying to implement a (hopefully portable!) tagged pointer class. Basically, I have my own allocator which will ensure alignment at 8- byte boundaries (where "byte" is "size of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.