c++ - What different between object created from initialization constructor and assign operator? -


compiler gcc 4.8.4 -std=c++11 flag assigned.

i've got compile error while compiling sample project.

ifstream f(this->pid_file_name()); string content(istreambuf_iterator<char>(f), istreambuf_iterator<char>()); pid_t pid = stoi(content); 

it pop error :

error: no matching function call ‘stoi(std::string (&)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> > (*)()))’      pid_t pid = stoi(content); 

however, if change string declaration this, every things goes fine :

ifstream f(this->pid_file_name()); string content = string(istreambuf_iterator<char>(f), istreambuf_iterator<char>());  pid_t pid = stoi(content); 

i know there differents way how create object instance, think should same, have no idea why initialization constructor can't work. have idea on this?

this function declaration:

string content(istreambuf_iterator<char>(f), istreambuf_iterator<char>()); 

see most vexing parse

one way fix use universal initialization syntax:

string content{istreambuf_iterator<char>(f), istreambuf_iterator<char>()}; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -