DynamicSdmProtocol::DynamicSdm* DynamicSdmSlaveProvider::master()
{
// Should always have a master
assert(m_devices.size() > 0);
return m_devices;
}
I am getting an error:
1 2
../../../src1/Hardware/DynamicSdmSlaveProvider.cpp:143:
error: cannot convert 'std::vector<DynamicSdmProtocol::DynamicSdm*, std::allocator<DynamicSdmProtocol::DynamicSdm*> >' to 'DynamicSdmProtocol::DynamicSdm*' in return
I am able to return individual elements of the vector for instance:
1 2 3 4 5 6 7
DynamicSdmProtocol::DynamicSdm* DynamicSdmSlaveProvider::master()
{
// Should always have a master
assert(m_devices.size() > 0);
return m_devices[0];
}
However, I need to pass the whole vector. How might I go about doing that?
std::vector<DynamicSdmProtocol::DynamicSdm*>& DynamicSdmSlaveProvider::master()
{
// Should always have a master
assert(m_devices.size() > 0);
return m_devices;
}
If you want to make a copy of the vector,
1 2 3 4 5 6 7
std::vector<DynamicSdmProtocol::DynamicSdm*> DynamicSdmSlaveProvider::master()
{
// Should always have a master
assert(m_devices.size() > 0);
return m_devices;
}
Normally, copies of vectors are normally avoided so I would go with the reference. Depends on the design of your program.