-2

I have an std::map mapping to objects which don't have default constructors. I need an iterator to iterate over the map, but the iterator needs a default constructor, how do I solve this?

std::map<MyClass1, MyClass2> MyMap; //No default constructor needed
std::pair<MyClass1, MyClass2> MapIterator; //Need default constructor to construct std::pair
bitmask
  • 32,434
  • 14
  • 99
  • 159
cynric4sure
  • 189
  • 1
  • 12

1 Answers1

3

Why do you think a pair is a map iterator? In your case a std::map<MyClass1, MyClass2>::iterator is a map iterator. And it is default constructible.

David
  • 27,652
  • 18
  • 89
  • 138