I defined a class “eventZone” which is used in my class “configuration”
class configuration { ... QMap<QString, eventZone> zones ... }
Until rescently I succesfully used a for loop like saw
for(eventZone evz : config.zone.values()) { ... }
However this doesnt work since I implemented a copy constructor for eventZone (needed to serialize it and be able to save configurations)
The error I get is
/home/.../zonedisplay.cpp:43: erreur : no matching function for call to 'eventZone::eventZone(eventZone&)'
My new constructor has type :
explicit eventZone(const eventZone &cpy);
How to make those two coexist ?
There is no reason to put
explicithere.explicit‘s job is to prevent implicit conversions, but you don’t convert – you just copy. Remove it. It’s only needed for single-argument constructors that have parameters of a different type than the class type itself.Anyways, the usual idiom in C++ is to take references (unless you explicitly need copies), and that applies to the range-based for-loop too: