mercredi 24 mai 2017

More than one round bracket in function call?

I've excercise where I need to write function. Function scheme look like

auto add(int a){
}

I need to be able to call this function with many brackets:

add(1)(2)(3); // 6
add(1)(2)(3)(4); // 10
add(1)(2)(3)(4)(5); // 15

But I can not figure out which C++ feature I should use in this case. I heard that I should use functors but I don't know if this is the best idea in this case.

Aucun commentaire:

Enregistrer un commentaire