type conversion question

B

bwalker

I have a question about type conversion. In the following code, what
would be the correct way to convert the variable idOut to an unsigned
short reference? I know that I'm going to loose precision but that is
okay.

typedef int Id;

bool function( Id& idOut, const std::string &name)
{
return obj->getXXX(name, (unsigned short&)idOut);
}

I should use reintrepret_cast<>, correct?

Thanks.

-brad w.
 
J

James Kanze

I have a question about type conversion. In the following
code, what would be the correct way to convert the variable
idOut to an unsigned short reference? I know that I'm going to
loose precision but that is okay.
typedef int Id;
bool function( Id& idOut, const std::string &name)
{
return obj->getXXX(name, (unsigned short&)idOut);
}
I should use reintrepret_cast<>, correct?

Only if you want undefined behavior.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top