That error means the copy constructor of the CvSVM
class is private; therefore you simply can't write valid code that requires a CvSVM
object to be copied. It follows that you can't copy a class containing a CvSVM
object, either, such as a pair. And calling map::insert
makes a copy.
The first thing you might want to do is check whether there is a newer version of the library that supports C++11. It's quite likely that the CvSVM
class can be moved even if it can't be copied. If so, this code ought to compile without modification against a newer version.
If not, but you have C++11 support, you can have the object constructed directly in a container, so that it doesn't need to be copied or moved at all. However, this is a bit tricky when the container is a map, since the value you have to construct is actually a pair whose second element is a CvSVM
. This is how you do it:
classes_classifiers.emplace(piecewise_construct, make_tuple(class_), make_tuple());
Another possibility, if you have C++11 support, is to store unique_ptr<CvSVM>
objects in your map instead of the CvSVM
objects themselves. The use of unique_ptr
guarantees that when you remove an element from the map, the object is delete
d:
map<string,unique_ptr<CvSVM>> classes_classifiers;
classes_classifiers.insert(make_pair(class_, unique_ptr<CvSVM>(new CvSVM())));
If you don't have C++11 support, your only option is to store raw pointers to CvSVM
in your map. This is less than optimal because it requires you to delete
each pointer before erasing it from the map, otherwise you'll leak memory.