I can see so many language who can define a function when passing it as argument. However there is something i cannot understand in C++, here is the snippet.
::android::hardware::camera::common::V1_0::Status err = ::android::hardware::camera::common::V1_0::Status::OK;
std::vector<std::string> devices;
hardware::Return<void> ret =
hidlSecureCamera->getCameraIdList([&err, &devices](
::android::hardware::camera::common::V1_0::Status idStatus,
const hidl_vec<hidl_string>& cameraDeviceIDs) {
err = idStatus;
if (err == Status::OK) {
for (size_t i = 0; i < cameraDeviceIDs.size(); i++) {
devices.push_back(cameraDeviceIDs[i]);
}
} });
As you can see, the prototype of getCameraIdList
is Return<void> SecureCamera::getCameraIdList(getCameraIdList_cb _hidl_cb)
. So it only accept one function as argument.
However, i cannot understand the meaning of [&err, &devices]
. They're already variables defined before. So i should be able to use it directly, why i need [&err, &devices]
?