This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Assign pointers of different objects to the same pointer
> Hi!
>
> Use void*:
>
> MyType1* var1;
> void* ptr;
>
> ptr = var1;
>
> // C-Style cast
> var1 = (MyType1*)ptr;
>
> // Dynamic cast, checks types at runtime
> var1 = dynamic_cast<MyType1*>(ptr);
>
> // Reinterpret cast does the same as C-Style cast (at least i think so)
> var1 = reinterpret_cast<MyType1*>(ptr);
> ....
>
> Also you may want to look at the other *_cast operators (static_cast,
> etc)...
>
> Sorry, i don't want to insult you, but this made me laugh ;o)
>
> Cheers, Markus
>
Maybe that work for you but I get this error:
"simulationview.cpp:26: Fehler: Ungültige Umformung von »void*« in »QWidget*«"
OR
simulationview.cpp:26: Fehler: dynamic_cast »SimulationView::ptr« (des Typs
»void*«) in Typ »class QWidget« (target is not pointer or reference) kann
nicht vorgenommen werden
So *ptr isn't typeless or on the other hand, gcc does type checking for void
*ptr.
So until gcc does not check the type behind a pointer in a special case I
can't belief that that will work.
And I want that result in not more than 2 lines of code like in any other
programming language.
If that would work, classes and c++ would be sensless.
The only way I see is to do it extern over the linker, because ld doesn't care
about types.
A other possibility I see is to use DCOP of KDE or linux system mechanism
(threading) or better write and read from terminal or file.
I guess that are going to be two days and 200 pages to read until I can solve
this problem.