Question

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 ]

Was it helpful?

Solution

  • 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(); 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top