void func::open()
{
RequestSession* psg = new RequestSession;
((RequestSession*)psg)->st开发者_如何学Go.ProVer = PRO_VERSION; //PRO_VERSION is macro
((RequestSession*)psg)->st.DevID = DEVICE_ID; //DEVICE_ID is macro
}
I could not understand what is the need for type casting once again as psg is the pointer of RequestSession class.
There is no need of typecasting here. It's redundant and removable.
Put simply, whenever you see a C-style cast in C++ code, it is wrong. For the very, very rare occasions when a cast is needed, you should be using static_cast
, or even more rarely reinterpret_cast
. The only cast that appears at all in my own code is dynamic_cast
, which is needed when you really need to find the type of something, but this too is quite rare.
精彩评论