对于这个虚假的 VS2010 C++ 是否有任何解决方法?智能感知错误
这是一些说明问题的示例代码。
它编译并运行正确,但 VS2010 编辑器 IntelliSense 抱怨 hold
变量并显示以下消息
IntelliSense:非静态成员引用必须相对于 特定对象
class tester
{
public:
void test()
{
int outer[] = {1,2,3};
int inner[] = {4,5,6};
std::for_each(outer, outer + _countof(outer), [&](int o) {
std::for_each(inner, inner + _countof(inner), [&](int i) {
hold.push_back(i + o);
});
});
}
private:
std::vector<int> hold;
};
int main(int argc, char* argv[])
{
tester().test();
return 0;
}
注意:如果只有一层 for_each (例如只是外部),那么很高兴
有其他人遇到过这种情况吗?如果是的话,有没有办法稍微改变它,以便 IntelliSense 高兴或者我被卡住了带有红色波浪线?
更新: 我已经下载了 VS11 的预览版,它对代码很满意 - 没有波浪线,所以至少它已在下一个版本中修复。
Here is some sample code that illustrates the problem.
It compiles and runs correctly, but the VS2010 editor IntelliSense complains about the hold
variable and shows the following message
IntelliSense: a nonstatic member reference must be relative to a
specific object
class tester
{
public:
void test()
{
int outer[] = {1,2,3};
int inner[] = {4,5,6};
std::for_each(outer, outer + _countof(outer), [&](int o) {
std::for_each(inner, inner + _countof(inner), [&](int i) {
hold.push_back(i + o);
});
});
}
private:
std::vector<int> hold;
};
int main(int argc, char* argv[])
{
tester().test();
return 0;
}
NB: It is happy if there is only one level of for_each (just outer for example)
Has anyone else come across this, and if so, is there a way to change it slightly so that the IntelliSense is happy or am I stuck with red squiggly lines?
UPDATE:
I have downloaded the preview of VS11 it is happy with the code - no squiggly lines, so at least it has been fixed for the next release.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是在寻找一种解决方法来安抚 VS2010 的智能感知,您可以像这样捕获外部 lambda 中的hold:
显式定义hold的类型或根据您认为合适的方式重命名该变量以使其清晰(由于懒惰而使用自动和名称隐藏)。
If you are just looking for a workaround to placate VS2010's intellisense, you can capture hold in the outer lambda like this:
Explicitly define hold's type or rename the variable for clarity as you feel is appropriate (using auto and name hiding due to laziness).