Classname* variableName = (Classname*) variableName2

Hi Guys,

I've taken it upon myself to learn C++ and I think I've got a pretty good understanding of pointers after a few days of research, but I'm curious about the above statement (Found at http://msdn.microsoft.com/en-us/library/ms810620 : Appendix A->in the CDXInput::DIEnumDevicesProc() function). Classname* variableName seems to make sense to me. You're creating a pointer variable to a class object. Its the statement on the right hand side of the equals confuses me: (Classname*) variableName2. Why would you need to encapsulate the pointer and the Classname on the right hand side of the equals?

thanks in advance for your responses.
Last edited on
closed account (zb0S216C)
It's a c-style cast. It's used to cast the type associated with the identifier (after the parentheses) to the type specified within the parentheses. It seems as though Microsoft favours c-style casts instead of C++'s casting operators. Sad, really.

Wazzak
Last edited on
Topic archived. No new replies allowed.