+ 1
Why typeid is different ?
Refer code below : Why I am getting different type id name for both the cout statements ? https://code.sololearn.com/cmnFNAvgMM8E/?ref=app
7 Respuestas
+ 1
Can't explain, but triggering a call to the parametric constructor yields similar outputs.
(Edited)
+ 1
Nice catch Ipang
I got idea about triggering a parametric constructor ..just passed parameter and I could observe the same output
Could you please elaborate on addition of default constructor ?
+ 1
Ketan
Apologies, my previous comment on default constructor was a mistake (comment removed).
I see now addition of default constructor didn't have any effect. Perhaps I forgot to remove an argument I used on instantion at line 20 on earlier test, and got wrong impression the similar outputs was due to addition of default constructor.
My bad 😁
+ 1
No problem... It's ok... Just wanted to check that I am not missing something
+ 1
Just got this behaviour as well
Let default constructor i.e. no argument provided into function as it is
Changed call from main function and remove argument value passed to make it same as what we have inside template function...
With both function calls having same thing, typeid is still different
+ 1
Ketan,
It's also funny that having the code as it is, and just use of uniform initializer on instantiation at line 20 yields similar outputs ...
cout << typeid(tempClass{}).name() << endl;
I wonder, whether tempClass() was misunderstood for a function declaration (confused)?
+ 1
True...
I also thought about function declaration at first like below
Class obj; means class constructor is called
Class obj(); means obj is function just declared which don't take argument and return type is of class type
Class obj(); is fine as it is called declaration and never called so no linker error
But is this case for our current scenario ?
This declaration line (if we assume that it is declaration) is a function parameter so it can't be a declaration ... This is what I feel to discard it as function declaration but not sure and totally confused