Ошибка C2664 в hid_device.h

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

Отладочный вывод:

hid_device.h (37): ошибка C2664:> 'std:: basic_string<_Elem, _Traits, _Ax>:: basic_string (std:: basic_string<_Elem, _Traits, _Ax>::> _ Has_debug_it)': невозможно преобразовать параметр 1 из 'unsigned long' to> 'std:: basic_string<_Elem, _Traits, _Ax>:: _ Has_debug_it' с [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ] Конструктор для структуры 'std:: basic_string<_Elem, _Traits, _Ax>:: _ Has_debug_it 'объявлен' явным 'с помощью [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ]

1 ответ

Решение
  • Опция 1:

Неправильно включает. У тебя должно быть #include <string>не #include <string.h> или любой другой вариант в верхней части файла.

  • Вариант 2:

m_devicePath является unsigned long (сомневаюсь в этом) и не может быть напрямую преобразован в std::string,

использование std::to_string() (C++ 11):

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

или stringstream (C++03) для преобразования unsigned long к std::string:

std::string get_path( void ) { 
     std::stringstream ss;
     ss << m_devicePath;
     return ss.str(); 
}
Другие вопросы по тегам