编译器警告C4930

来源:互联网 发布:php 随机红包算法 编辑:程序博客网 时间:2024/05/21 12:12

问题代码

  std::string cfg_file_path("./xxxx.cfg");  std::fstream fin(cfg_file_path.c_str(), std::ios_base::in);  std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());  //stream_buffer_content.c_str();//this line compliled error

编译器把 stream_buffer_content当做一个函数声明了。函数类型是 std::string (*)(std::istreambuf_iterator<char>, std::istreambuf_iterator<char>(*)());

如果你这样写的话,编译器提示无法解析的外部命令,说明stream_buffer_content确实是个函数声明

std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());        stream_buffer_content(std::istreambuf_iterator<char>(fin), 0);

解决方案:

  std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), (std::istreambuf_iterator<char>()));
  std::istreambuf_iterator<char> end;  std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), end);
  std::string stream_buffer_content;  stream_buffer_content.assign(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());

参考

编译器警告(等级 1)C4930 错误
stackoverflow http://stackoverflow.com/questions/12041509/possible-compiler-bug-for-c4930

总结

所有的警告都是错误

0 0
原创粉丝点击