【发布时间】:2019-04-09 18:22:57
【问题描述】:
当我在 C++ 方法中使用 BOOST_FOREACH 宏时,不再自动检测到实现,因为该方法被强制退出由 Visual Studio 确定的相应命名空间(可能是 Intellisense?)。编译没有问题。这是怎么回事?
.h
class testClass
{
public:
testClass();
~testClass();
void print();
};
.cpp
#include "testClass.h"
#include "stdafx.h"
#include <boost/foreach.hpp> // BOOST_FOREACH
#include <iostream> //std::cout, endl
testClass::testClass()
{
}
testClass::~testClass()
{
}
void testClass::print()
{
int nums[] = { 1, 2, 3, 4, 5 };
BOOST_FOREACH(const int a, nums)
{
std::cout << a << std::endl;
}
}
【问题讨论】:
-
“不再自动检测到实现”是什么意思?您遇到的具体问题是什么?
-
顺便说一句,您使用的是哪个 VS?从 VS2012 开始,您应该可以使用基于 C++ 范围的 for 而不是
BOOST_FOREACH。 -
我认为您认为有关智能感知引擎的事情毫无意义。这与“命名空间”几乎没有关系(可能:没有)。相反,这是 Intellisense 没有正确理解预处理源的情况。这可能有很多原因。事实上,如果智能感知丢失,代码编译得很好。
-
像stackoverflow.com/… 这样的搜索将证明来自 Intellisense 的不一致的行为非常普遍,而且原则上无法真正解决(除此之外:您可以尝试使用较新版本的 Visual Studio)
-
@LightnessRacesinOrbit 虽然方法的实现在.cpp中,但是VS检测不到,下拉列表中也没有出现方法
标签: c++ visual-studio boost foreach namespaces