The compiler is correct to reject this line:
MgrBlks mgr_n_blks { {"T2M_NAME", NULL} };
In C++11 std::pair
has a template constructor that takes any argument types, then converts them to the members:
template<typename X, typename Y>
pair(X&& x, Y&& y)
: first(std::forward<X>(x)), second(std::forward<Y>(y))
{ }
NULL
must be defined as 0
or 0L
or something similar, so template argument deduction deduces the constructor's template arguments as const char*
and (with GCC) long
. The first argument type is convertible to std::string
but long
is not convertible to CI_RecordInfo_Vector*
, so the constructor cannot be called.
For the other case with a map of structs there is no argument deduction, the RHS of the assignment must be convertible to the struct type, and in that case NULL
is used to directly initialize the struct's first member, rather than first being deduced as a long
and initializing a long
, which cannot be converted to a pointer.
Do not use NULL
in C++11, nullptr
was invented to avoid exactly these problems, you should use it.
A possible workaround would be to cast the argument to the right type:
MgrBlks mgr_n_blks { {"T2M_NAME", (CI_RecordInfo_Vector*)NULL} };
but it's simpler and clearer just to use nullptr
.