+ 2

what is the output of this code? template<class t> void f(t){ static int I=0; cout<<I++; } int main (){ f(1); f(1.0); f(1); }

26th Jul 2016, 3:05 PM
Darsh Shah
Darsh Shah - avatar
5 Réponses
+ 2
012. type doesn't matter. also use typename instead of class in the template
27th Jul 2016, 4:58 AM
_Geometry dash_ _Roh_ (AKA NovaRate0315)
_Geometry dash_ _Roh_ (AKA NovaRate0315) - avatar
+ 1
If the code of function is cout<<I++; The answer will be 001. If code is cout<<++I; Then answer will be 112.
26th Jul 2016, 3:59 PM
Harkirat Singh
Harkirat Singh - avatar
0
geometry: i thought putting class or typename was absolutely the same, and iirc on cppreference it puts so.
27th Jul 2016, 4:41 PM
ddrodoric
0
can someone explain reason for the answer?? Also why it gets compiled even though there is no variable in the function parameters("void f(t)")??
14th Sep 2016, 5:59 AM
kamal joshi
kamal joshi - avatar
- 4
no output as f( t ) is just declared not defined
26th Jul 2016, 3:30 PM
Tara Prakash