quote:Original post by sjelkjd
Ok then, so a question: which is better style?
int i=float(f);
or int i=static_cast<float>(f);
Mind if I add some more?
....
OR
int i = (float)f;
is the assembly output the same for all?
quote:Original post by sjelkjd
Ok then, so a question: which is better style?
int i=float(f);
or int i=static_cast<float>(f);
// say we have a new thread, and we want to convert the LPVOID parm to a pointer to some class, say CFooDWORD WINAPI ThreadProc(LPVOID pContext){ union { LPVOID pVoid; CFoo* pFoo; } uCaster; uCaster.pVoid = pContext; // you can now make calls on uCaster.pFoo CFoo* pObj = uCaster.pFoo; pObj->SomeMethod(); // or just uCaster.pFoo->SomeMethod();}
vector<int> v(istream_iterator<int>(cin),istream_iterator<int>());
int i(int(f));
quote:Original post by Promit
WHat is the advantage over simply casting it, though?
quote:Original post by Anonymous Poster
In C++ the following is legal:
float* fp;
fp = new float(2);
on the second line a constructor is being called, there are no casts.