The compiler correctly rejects this line:
MgrBlks mgr_n_blks { {"T2M_NAME", NULL} };
In C ++ 11, std::pair has a template constructor that takes any types of arguments and then converts them to 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 the output of the template argument outputs the arguments of the constructor template as const char* and (with GCC) long . The first type of argument is converted to std::string , but long not converted to CI_RecordInfo_Vector* , so the constructor cannot be called.
For another case with a structure map, there is no argument output, the assignment RHS must be converted to a structure type, in which case NULL used to directly initialize the first structure element, and is not first displayed as long and initializes a long , which cannot be converted to a pointer .
Do not use NULL in C ++ 11, nullptr was invented, in order to avoid precisely these problems, you should use it.
A possible workaround would be to cast the argument to the correct type:
MgrBlks mgr_n_blks { {"T2M_NAME", (CI_RecordInfo_Vector*)NULL} };
but itβs easier and more understandable to use nullptr .
Jonathan wakely
source share