c++ - What different between object created from initialization constructor and assign operator? -
this question has answer here:
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>());
one way fix use universal initialization syntax:
string content{istreambuf_iterator<char>(f), istreambuf_iterator<char>()};
Comments
Post a Comment