Hi all,
My first post here -- I've been trying to update some old code that uses C-style casts into the C++ equivalent, and I've stumbled on one cast that I can't figure out how to convert.
This isn't the code that was giving me issues, but it reproduces the problem:
Old code would look like this:
short g_myshort;
const short& someFunction()
{
return g_myshort;
}
int main()
{
g_myint = 5;
int* pnum = (int*)(&someFunction());
}
I'd like to replace that last call with something like:
int* pnum = static_cast<int*>(&someFunction());
or possibly
const int* pnum = static_cast<const int*>(&someFunction());
but in both cases, the compiler yells: cannot convert from 'const short *__w64' to int */const int*.
I've tried nesting a const_cast inside the static_cast, and vice versa, but neither has worked. Any ideas? Or am I forced to stick to the C style cast here.
And yes, I realize I could store the return value and get it done that way, but I'm interested from a theory angle on why the C-style cast can get it done in one line and the C++-style seemingly can't.
Thanks!