c++ - C++11 / Genrated constructor -


i have been working on c++ project started else (who left company). has written piece of code seems work pretty cannot understand it.

here below simplified version of code:

there 2 classes :

class algo_t { protected :     matrix_t m_matrix ; public:     algo_t(matrix_t && matrix) {         dosomething();     } };  class matrix_t { protected :     std::ifstream & m_iftsream ; public:     matrix_t(std::ifstream && ifstream) {         dosomething();     } }; 

in main:

there following call in main function:

char * pmyfilename = agrv[1] ; algo_t myalgo(ifstream(pmyfilename)); 

first surprised code compiled without error because there no constructor of algo_t taking ifstream parameter. more surprised notice code works well.

are constructor generated compiler or there new feature introduced c++11 (with rvalue...)?

in c++ allowed 1 user defined conversion. cannot directly construct algo_t ifstream can construct matrix_t ifstream. in

algo_t myalgo(ifstream(pmyfilename)); 

the compiler construct temporary matrix_t(your 1 user defined conversion) , use temporary construct myalgo


Comments