C++: Default initialize an integral type in a template function -


for educational purposes wrting own c++ numerical vector template class. want able write (v, w) dot product of 2 vectors , consequently overload operator,() follows:

template<class t> const t vector<t>::operator,(const vector<t>& v) const {     assertequalsize(v);      t t;     for(size_t i=0; i<numelements; i++) {         t += elements[i] * v[i];     }     return t; } 

my question is: how initialize t sensible value (e.g. 0.0 vector<double>)? tried t t(); g++ tells me, e.g., "double(*)()" cannot converted "const double" @ return statement , operator+=() not defined "(double(), double)".

thank much!

what need termed value initialization, has effect of zero-initializing built-in types:

t t{};     // c++11 t t = t(); // c++03 , c++11 

the reason doesn't work

t t(); 

is declaration of parameterless function called t, returning t.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -