| View previous topic :: View next topic |
| Author |
Message |
w.kosma
Joined: 28 Oct 2005 Posts: 19
|
Posted: Sun Dec 18, 2005 12:56 am Post subject: vertex* conversion in c++ |
|
|
hello,
i`m new here and to pspdev,
i was playing with some source code,
i wanted to mix some examples, one of which in c another in c++,
i get only one error about invalid conversion
from this line (taken from c example):
struct Vertex* vertices = sceGuGetMemory((NUM_VERTICES+1) * sizeof(struct Vertex));
any ideas how to do it in c++
i would be very grateful for any help,
thanks,
wojciech |
|
| Back to top |
|
 |
Dr. Vegetable
Joined: 14 Nov 2005 Posts: 171 Location: Boston, Massachusetts
|
Posted: Sun Dec 18, 2005 1:28 am Post subject: |
|
|
The compiler is just warning you (forcefully) that you are taking a pointer to an anonymous block of memory and using it as a specific type. Just use a "cast" to tell the compiler that you know what you are doing:
struct Vertex* vertices = (struct Vertex*)sceGuGetMemory((NUM_VERTICES+1) * sizeof(struct Vertex));
Hope this helps! |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sun Dec 18, 2005 8:04 am Post subject: |
|
|
sceGuGetMemory() returns type void *. You're assigning it to type struct Vertex *.
In C, all pointer types are compatible with void *, so you can just make the assignment.
In C++ the cast is mandatory, as Dr.Vegetable has shown.
One very common place this happens is when C++ programs use malloc, which also returns void *.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
|