I have a pointer to a pointer to an object that will not be mutated, so I thought making the whole chain const would help prevent me from accidentally making changes the the object. const IMMDeviceCollection* const* const ppMMDeviceCollection
When I try to call the methods I need, the compiler says it cannot convert a const object to a reference on this line (*ppMMDeviceCollection)->GetCount(&nMMDevices);
Here is what I am doing:
HRESULT getAudioEndpointSpeakerIndices(const IMMDeviceCollection* const* const ppMMDeviceCollection,
std::vector<int> iSpeakers) {
HRESULT hr;
UINT nMMDevices;
IMMDevice* pMMDevice = NULL;
IPropertyStore* pPropertyStore = NULL;
PROPVARIANT property;
// Initialize container for property value.
PropVariantInit(&property);
hr = (*ppMMDeviceCollection)->GetCount(&nMMDevices);
if(hr != S_OK) { goto EXITGAES; }
for(ULONG i = 0; i < nMMDevices; i++) {
hr = (*ppMMDeviceCollection)->Item(i, &pMMDevice);
if(hr != S_OK) { goto EXITGAES; }
hr = pMMDevice->OpenPropertyStore(STGM_READ, &pPropertyStore);
if(hr != S_OK) { goto EXITGAES; }
hr = pPropertyStore->GetValue(PKEY_AudioEndpoint_FormFactor, &property);
if(hr != S_OK) { goto EXITGAES; }
if(property.uintVal == Speakers) {
iSpeakers.push_back(i);
}
}
EXITGAES:
SAFE_RELEASE(pMMDevice);
SAFE_RELEASE(pPropertyStore);
return hr;
}
If I remove the const from the pointer to the pointer, the code runs fine. IMMDeviceCollection* const* const ppMMDeviceCollection
Why is this legal, but the above not?
Is there some way to call functions from a const IMMDeviceCollection* const* const ppMMDeviceCollection
?