warning: format '%d' expects argument of type 'int', but argument 4 has type 'std::vector<NmsObject>::size_type {aka long unsigned int}' [-Wformat=]

这个警告提示你在使用格式化函数(例如 printf)输出一个数字时,所使用的格式字符串和实际传递的参数的类型不匹配。

例如,在代码中,可能有一行代码像这样:

printf("The size of the vector is %d\n", myVector.size());

但是,在这里,myVector.size() 返回的是一个 std::vector<NmsObject>::size_type 类型的值,而格式字符串 %d 则期望一个 int 类型的值。因此,编译器会发出警告。

为了解决这个问题,需要使用正确的格式字符串来输出 std::vector<NmsObject>::size_type 类型的值。例如,可以使用 %zu 来输出一个无符号整型值:

printf("The size of the vector is %zu\n", myVector.size());

另外,也可以使用 C++ 的输入输出流来输出这个值,例如:

std::cout << "The size of the vector is " << myVector.size() << std::endl;

这种方法更加类型安全,并且不会出现这种警告。