I am writing a generic function as shown below.
template<class Iterator, class T> void foo(Iterator first, Iterator last) { T a; cout << a << endl;
These functions print the undefined value for the variable a , and if I change the initialization to
I see that the initialized value is 0 , as I expect.
If I call T a , the variable is initialized to the default value, but if I call T a = T() , I believe that due to optimization, the copy constructor should be called with the value T() , which is still the default value.
I canβt understand what is the difference between these two lines and why is this happening?
c ++ initialization generic-programming templates function-templates
Abruzzo forte e gentile
source share