我有一个foo(char *n, ...);
我需要获取并使用所有可选char参数的函数.我有个想法
while(va_arg(argPtr, char) != NULL)
{
...
}
Run Code Online (Sandbox Code Playgroud)
了解何时到达列表的末尾.那么,它会起作用,如果在函数调用中我会这样做foo(n, 't', 'm', '$', NULL);吗?
将NULL被va_arg读作char?或者可能有更常用的方法来确定列表的结尾,而不添加NULL最后一个参数?
我使用polinoms并将它们作为度和系数保存在std :: map中.这是代码片段:
std::map<int,int> pol;
Run Code Online (Sandbox Code Playgroud)
地图填充了数据,然后我开始处理它.
for(std::map<int,int>::iterator it = pol.begin(); it != pol.end(); it++) {
if( it->first != 0 ) {
it->second *= it->first;
it->first--;
}
else {
it->first = 0;
it->second = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
从它开始 - >第一次 - 进一步我得到了非常大的输出,有错误error: decrement of read-only member ‘std::pair<const int, int>::first’
it->first--;
^~
或者error: assignment of read-only member ‘std::pair<const int, int>::first’
it->first = it->first - 1;
为什么它是只读?我该如何解决?
$ g++ --version
g++ (Debian 6.3.0-5) 6.3.0 20170124
Run Code Online (Sandbox Code Playgroud)