Best Answer AceInfinity , 05 October 2014 - 12:40 PM
A C cast is less safe than using a pre-defined C++ style cast, however understand that a C cast "chooses" the best cast by assumption based on what you're trying to cast. You definitely do not understand these principles and it seems like you are guessing more than anything... That's okay, but it won't get you very far with C++ because this is a language where you really need to understand how your code works and how the language works in order to be successful; much less forgiving than most other languages. I'd suggest looking up some online documentation for casts, perhaps some tutorials on pointers & reference, just to start.
Additionally, Instead of using a pointer for 'Infos' from GetInfos(), why not a reference? It would help you avoid having to dereference each time you want to change the value.
It looks like (even though it's a bad attempt) that you're still trying to do the improper thing and setting the address of 'Infos' to the version, based on what I gather from what you think your code should be doing, and what I'd assume you WANT to do.
*Infos = MAJOR_VERSION;
*Infos = MINOR_VERSION;Infos is a pointer type, you need to dereference it to change it's value, otherwise you'll be changing the pointer/address itself and not what it points to. You probably naively used reinterpret_cast due to compiler errors you were getting about not being able to assign to the variables due to pointer and int conflicts.
My suggestion would be to not do this in the future and understand what you're trying to do and why those compiler warnings and errors are displaying after you attempt to compile. Mainly because even if you managed to get a hacky cast to work in a certain case, it doesn't mean that the program at runtime will demonstrate defined behavior, nor does it mean that it'll work as you expect it to.
Aside from that, I don't quite understand the point of this due to the fact that these are pre-defined by you:
unsigned const MAJOR_VERSION = 1; unsigned const MINOR_VERSION = 0;I can't see these being meaningful? :S And there's a signdedness factor here from unsigned to a signed integer as well.
There are better ways to accomodate version updates than this. Go to the full post