Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 double 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

like image 549
F. P. Avatar asked Aug 29 '26 12:08

F. P.


1 Answers

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);
like image 170
Georg Fritzsche Avatar answered Sep 01 '26 01:09

Georg Fritzsche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!