Lionel Zhou said:
Dear Group;
Say i have to convert a point of class A to class B.
Did you mean structs? C doesn't have C++ classes.
If i use (B
*)pointer_of_class_A it won't pass compilation but if i use (B *)(void
*) pointer_of_class_A it will compile.
If you need the cast, the conversion is almost certainly very very
unwise indeed. I recommend you find a different way to achieve your
objective.
My question is that is there a better way to do this?
Yes. If you need an A, use an A. If you need a B, use a B. If you need
to convert an A to a B, write a function that takes a pointer-to-A and
a pointer-to-B, and populates the one from the other as appropriate.
i have tried the c++ style reinterpret_cast
like reinterpret_cast<B>pointer_of_class_A it doesn't work either.
That's because C doesn't have that syntax.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.