MFC beginner here.
I've tried to initialize std::map like this: (in the header of CView)
// myprogramView.h
std::map<int, CStatic> myMap = {{10,{}}, {11,{}}};
But the compiler complains "no instance of constructor ... matches the argument list".
(Edit for future reference) The above message was an error from IntelliSense. The compiler(MSVC) says: C2664 'std::map<int,CStatic,std::less,std::allocator<std::pair<const _Kty,_Ty>>>::map(std::initializer_list<std::pair<const _Kty,_Ty>>)': cannot convert argument 1 from 'initializer list' to 'std::initializer_list<std::pair<const _Kty,_Ty>>'
However, we can do these kinds of initializations:
std::map<int, std::string> myMap2 = { {10,{}}, {11,{}} };
std::map<int, std::map<std::string, int>> myMap3 = { {10,{}}, {11,{}} };
Why doesn't the first example compile, and how can I use a map containing MFC objects?
I'm trying to access the control object in the map and .Create() it during the run-time or in the OnCreate.
I also tried CMap but it seems the same problem occurs.
Question resolved by j6t's answer. Just want to clarify that the answer is talking about std::initializer_list, not 'member initializer list'.
std::mapwith values that aren't ultimately going to be used. What's the real problem you are trying to solve here?CStatics would be convenient, since I can access them by key. (the key will be different in the for loop). Maybe I could use std::vector, etc., this was just a quick idea.CWnd::GetDlgItemturns a control ID into a control. Or simply callCWnd::SetDlgItemText.CWnd, so you can just use those members as is.