J
JKop
unsigned int CheesePlain(void)
{
unsigned int const chalk = 42;
return chalk;
}
unsigned int& CheeseRef(void)
{
unsigned int const chalk = 42;
return chalk;
}
int main(void)
{
unsigned int plain = CheesePlain();
unsigned int ref = CheeseRef();
}
Now, consider that the return type is not unsigned int, but some other class
name that prints out stuff via cout in its constructor, copy constructor,
assignment operator. Will you find that there's a difference in the two
separate printouts, ie. that the "plain" one will create one more temporary
than the reference version?
-JKop
{
unsigned int const chalk = 42;
return chalk;
}
unsigned int& CheeseRef(void)
{
unsigned int const chalk = 42;
return chalk;
}
int main(void)
{
unsigned int plain = CheesePlain();
unsigned int ref = CheeseRef();
}
Now, consider that the return type is not unsigned int, but some other class
name that prints out stuff via cout in its constructor, copy constructor,
assignment operator. Will you find that there's a difference in the two
separate printouts, ie. that the "plain" one will create one more temporary
than the reference version?
-JKop