How does std::map construct complex objects?

How does std::map construct complex objects if no constructor is written for it?

1
2
3
4
5
6
7
8
9
class Complex{
	float a,b,c;
};

void main(){
	map<int,Complex>  Test;

	Complex &Item = Test[0];
}


Item's members are all zeroed out.
If you don't explicitly declare a constructor, the compiler generates a default one and map uses that one.
True, but the default constructor doesn't zero out the members. Just as declaring an int without initializing it will provide a random value.

Unless there is a default constructor that does this, is there?
It will. If you do something like:

int a;, then a is not initialized.

However, inside a template class, ints are intialized to 0 if you construct them, so you can do stuff like this:

1
2
3
4
5
template <class T>
T some_func() {
    T _type = T();
    //...
}
Topic archived. No new replies allowed.