lundi 25 mai 2015

Function with one local parameter of default value

I`m trying to find a method that compiles without error and does the fallowing thing :

template <class A>
void f(A a,A b=a){
//do something
}

But when I call this function like f<int>(3) the compiler tell me that local variable a may not appear in the context. I suppose that this is because the compiler can not know if a value would be assign to formal parameter a so that it could initialize formal parameter b with the value of a.

Is there any equivalent way/mode that i can implement such a function?

Aucun commentaire:

Enregistrer un commentaire