views:

117

answers:

1

Hello all,

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

+4  A: 

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);
Georg Fritzsche
`double volume_prisma(const double ` then?
Francisco P.
@Francisco: Yep, i took the liberty of ommiting the rest.
Georg Fritzsche
Works, thank you very much.
Francisco P.