我试图将function 对象作为另一种方法的参数传递,以便灵活地从列表中获取元素。这是我的代码:libusb_device * UsbKeyboard::GetSpecifiedDevice(function<bool(libusb_device *)> pred){ if (_usbDevices == nullptr) return nullptr; int i = 0; libusb_device *dev = nullptr; while ((dev = _usbDevices[i++]) != NULL) { if (pred(dev)) return dev; } return nullptr;}libusb_device * UsbKeyboard::GetHidDevice(){ function<libusb_device *> pred = [&](libusb_device *dev) -> bool { struct libusb_device_descriptor desc; int r = libusb_get_device_descriptor(dev, &desc); if (r >= 0) return desc.bDeviceClass == LIBUSB_CLASS_HID; }; return GetSpecifiedDevice(pred);}编译错误位于此代码的第一行: error C2027: use of undefined type 'std::_Get_function_impl<_Fty>'1> with1> [1> _Fty=libusb_device *1> ]1> usbkeyboard.cpp(111) : see reference to class template instantiation 'std::function<libusb_device *>' being compiled1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(551): error C2504: 'type' : base class undefined1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(554): error C2027: use of undefined type 'std::_Get_function_impl<_Fty>'1> with1> [1> _Fty=libusb_device *1> ]1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(554): error C2146: syntax error : missing ';' before identifier '_Mybase'1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(554): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int它说function 的基类是未定义的。为什么? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您在function<libusb_device *> pred中输入错误它应该是function<bool(libusb_device *)> pred或者只是auto pred关于c++ - 如何在Visual C++ 2013中将函数对象作为参数传递?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31785210/ (adsbygoogle = window.adsbygoogle || []).push({}); 10-09 18:39