Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对于C++;_C++_Foreach_Compiler Errors - Fatal编程技术网

C++ 对于C++;

C++ 对于C++;,c++,foreach,compiler-errors,C++,Foreach,Compiler Errors,我已经在两台不同的机器上编译了我的代码,我认为它们的设置是相同的。但是,一个编译没有问题,另一个给出以下错误 LogEventReader.cpp(320) : error C3861: 'for_each': identifier not found, even with argument-dependent lookup 有关守则: #include <algorithm> ... for_each(messages.begin(), messages.end(), proc

我已经在两台不同的机器上编译了我的代码,我认为它们的设置是相同的。但是,一个编译没有问题,另一个给出以下错误

LogEventReader.cpp(320) : error C3861: 'for_each': identifier not found, even with argument-dependent lookup
有关守则:

#include <algorithm> 
...
for_each(messages.begin(), messages.end(), processXMLMessage);
#包括
...
对于每个(messages.begin()、messages.end()、processXMLMessage);

你知道这是什么问题吗?TIA。

一个可能的问题是,第一个编译器需要使用命名空间std的
用于每个
)之前,code>,而第二个标识符是过度许可的,不需要它


当然,正如其他答案和评论激烈指出的那样,可能有更好的选择,例如在每次出现时明确拼写
std::for_each
,或者使用using声明(
使用std::for_each;
),而不是更广泛的using指令(
使用名称空间std;
)--但是这个(好的)建议并不能回答您的问题,即为什么一个编译器会诊断错误,而另一个编译器不会;-)。

请尝试
std::for_each()
。也许它看不到名称空间。

是的,我刚刚意识到这一点,它解决了这个问题。使用名称空间std!来吧使用名称空间std是邪恶的-谁知道什么时候会发生名称冲突?为什么ADL不能在这里工作,除非“messages”的迭代器不在std名称空间中?