C++ – Problem with std::multimap


I've got the following :

enum Type 
{ One = 0, Two};

class MySubClass
MySubClass(); // prohibited
MySubClass(const MySubClass&); // prohibited
MySubClass & operator (const MySubClass&); // prohibited
public :
MySubClass(int x);

class MyClass 
MyClass(int x) : m_x(new SubClass(x)) 
{ delete m_x; }
private :
MySubClass * m_x;

typedef multimap<Type, MyClass> my_multimap;
typedef pair<Type, MyClass> my_pair;

I'm trying to do the following :

my_multimap my_map;
my_map.insert(my_pair(One, MyClass(5)));

And I'm getting an unhandled exception result, the app is trying to read 0xfeeefeee etc.

What's going on? How can I fix this?
Please note that this is a simplified case of what I'm dealing with;

Best Solution

MyClass has no copy constructor defined. However, std::pair will need to make use of the copy constructor for MyClass. Presumably it is using MyClass's default copy constructor, which will give copy constructed objects copies of the pointer m_x. And when they get destroyed, you'll be facing multiple deletions.