Error C2664 in hid

std::string get_path( void ) { return m_devicePath; }

Debug output:

hid_device.h(37) : error C2664: >'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::>_Has_debug_it)' : cannot convert parameter 1 from 'unsigned long' to >'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it' with [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ] Constructor for struct 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it' is declared 'explicit' with [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ]


  • Option 1:
  • Wrong includes. You should have #include <string> , not #include <string.h> or any other variation at the top of the file.

  • Option 2:
  • m_devicePath is an unsigned long (doubt that) and can't be directly converted to std::string .

    Use std::to_string() (C++11) :

    std::string get_path( void ) { return std::to_string(m_devicePath); }
    

    or a stringstream (C++03) to convert the unsigned long to a std::string :

    std::string get_path( void ) { 
         std::stringstream ss;
         ss << m_devicePath;
         return ss.str(); 
    }
    
    链接地址: http://www.djcxy.com/p/68426.html

    上一篇: 模板类在C ++中产生错误

    下一篇: 隐藏错误C2664