C++ - Optional arguments by reference
I have an exam on C++ coming up, and I'm solving a few ones from past years. I have this question in one of them:
A function calculates the volume of a prysm. Arguments passed are height, depth and width. Arguments and return value are doubles Depth is optional and should default to 10. Hypothesis 1: All parameters are passed by value
I answered double volume_prysm(const dou开发者_如何学编程ble width, const double height, const double depth = 10);
Hypothesis 2: All parameters are passed by reference
How can I define a reference parameter in order for it to default to 10?
Thanks for your time!
PS: Sorry y'all for not translating
I don't know if that is what the question was aiming at, but temporaries can be bound to const references:
double volume_prisma(const double& largura, ..., const double& depth = 10);
精彩评论