C++ PCH警告:标头停止不能在宏或#if block-visualc++;2010年快车SP1

C++ PCH警告:标头停止不能在宏或#if block-visualc++;2010年快车SP1,c++,visual-c++,C++,Visual C++,这是从一个网站上粘贴的,该网站可能正在运行。我做了一些谷歌搜索,发现我现在的问题是VisualC++ 2010 SP1的结果,我今天下载了,现在给了我这个错误: PCH警告:标头停止不能在宏或#if块中。 希望有人能在这方面帮助我 #ifndef APP_STATE_H #define APP_STATE_H #include "Framework.h" class AppState; //this line is giving me the error //define two clas

这是从一个网站上粘贴的,该网站可能正在运行。我做了一些谷歌搜索,发现我现在的问题是VisualC++ 2010 SP1的结果,我今天下载了,现在给了我这个错误:

PCH警告:标头停止不能在宏或#if块中。

希望有人能在这方面帮助我

#ifndef APP_STATE_H
#define APP_STATE_H

#include "Framework.h"

class AppState; //this line is giving me the error

//define two classes

#endif
框架.h:

#ifndef OGRE_FRAMEWORK_H
#define OGRE_FRAMEWORK_H

#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreOverlay.h>
#include <OgreOverlayElement.h>
#include <OgreOverlayManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>

#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>

class OgreFramework : public Ogre::Singleton<OgreFramework>,OIS::KeyListener,OIS::MouseListener{
public:
    OgreFramework();
    ~OgreFramework();

    bool initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener = 0, OIS::MouseListener *pMouseListener = 0);
    void updateOgre(double timeSinceLastFrame);

    //OIS
    bool keyPressed(const OIS::KeyEvent &keyEventRef);
    bool keyReleased(const OIS::KeyEvent &keyEventRef);
    bool mouseMoved(const OIS::MouseEvent &evt);
    bool mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id);
    bool mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id);

    Ogre::Root* mRoot;
    Ogre::RenderWindow* mRenderWnd;
    Ogre::Viewport* mViewport;
    Ogre::Log* mLog;
    Ogre::Timer* mTimer;

    //OIS
    OIS::InputManager* mInputMgr;
    OIS::Keyboard* mKeyboard;
    OIS::Mouse* mMouse;
private:
    OgreFramework(const OgreFramework&);
    OgreFramework& operator= (const OgreFramework&);
};

#endif
\ifndef OGRE\u框架
#定义食人魔框架
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
OgreFramework类:公共Ogre::Singleton、OIS::KeyListener、OIS::MouseStener{
公众:
OgreFramework();
~OgreFramework();
bool initOgre(Ogre::String wndTitle,OIS::keystener*pKeyListener=0,OIS::mouseStener*pmouseStener=0);
void updateOgre(双timeSinceLastFrame);
//OIS
按下布尔键(常量OIS::KeyEvent和keyEventRef);
bool keyReleased(常量OIS::KeyEvent和keyEventRef);
bool mouseMoved(const-OIS::MouseEvent&evt);
bool-mousePressed(const-OIS::MouseEvent&evt,OIS::MouseButtonID);
bool-mouseereleased(const-OIS::MouseEvent&evt,OIS::MouseButtonID);
食人魔::根*mRoot;
食人魔:RenderWindow*mRenderWnd;
食人魔::视口*mViewport;
Ogre::Log*mLog;
食人魔::计时器*mTimer;
//OIS
OIS::InputManager*mInputMgr;
OIS::键盘*mKeyboard;
OIS::鼠标*mMouse;
私人:
OgreFramework(const OgreFramework&);
OgreFramework&运算符=(const OgreFramework&);
};
#恩迪夫

您可能使用了一个项目模板开始,并丢弃了预生成的源代码文件。这些项目模板喜欢打开预编译头,因为这样可以节省时间。在“解决方案资源管理器”窗口中的“属性”、“C/C++”、“预编译头”中右键单击项目。将“Precompiled Header”设置更改为“Not Using”。

我也有同样的问题,正在寻找解决方案。以下几点对我很有用:


在文件开头添加
#pragma一次
(甚至在
#ifndef APP_STATE_H
头保护之前)

这可能晚了一天,而且少了一美元,但我不小心将头文件放在了.cpp文件而不是.H文件中,因此犯了同样的错误。不过我会发布它,以防它对某人有所帮助。

我刚刚在头文件中添加了一个引用(#include“header.h”),这很有帮助。

将#include语句移到#if#end block之外。

我发现我的.h文件实际上被视为.cpp文件!右键单击解决方案资源管理器>所有配置>项类型:C/C++标题中的文件


确保项目类型不是C/C++编译器或其他。

一旦添加.cpp文件并使其包含标题,此错误将消失。我读过一些其他地方的错误。重建IntelliSense数据库解决了这个问题

  • 关闭Visual Studio
  • 删除[SolutionName].sdf
  • 删除DllWrappers.opensdf
  • 删除ipch文件夹
  • 开放式Visual Studio
  • 1.关闭项目。 2.重新打开项目,一切正常。
    这是我的经验。

    我也有同样的问题。我的解决办法是添加一个缺少的“;”在类定义的末尾。虽然这似乎不适用于您的问题,但其他出现相同错误的人可能会发现这很有帮助。

    我使用Visual Studio编辑Linux项目。对我来说,当我在预编译头文件中包含string.h时,问题就出现了。这是由包含_asm语句的行引起的,例如:

    __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
    
    解决方案是在“项目属性”、“配置属性”、“C/C++”、“预处理器”、“预处理器定义”下定义以下宏:

    __asm(x)=
    

    Framework.h
    中有什么?显示代码。那是哪个文件?你使用预编译头吗?因为这就是PCH的意思。你有StdAfx.h文件吗?我们可能需要查看您的整个包含图片,以了解错误的来源。似乎有一个uncoed#if块somewhere.BTW,if Framework.h包含预编译头,这很可能是错误。尝试将其include移到#if/#endif头保护之外(或者改用#pragma一次),看看会发生什么。这里没有预编译头。请参见编辑for Framework.ht此处没有包含AppState.h的文件,否则我会显示它!通过进一步的谷歌搜索,这是VisualStudio中的一个bug,但是一旦cpp文件中包含有问题的头,这个bug就会得到解决,这将是一个错误。如果你感兴趣,这里有一个人比我和微软的回答更能描述这个问题:不,我没有使用它,也没有预编译的头。这对我也很有用,谢谢。你知道潜在的问题是什么吗?@MarkStorer从上一篇文章的链接中得到了最好的解释-Intellisense引擎对头文件有一个停止并且没有包含在任何.c/.cpp文件中感到不高兴。@Kash链接已经死了。向上投票,但我个人不想用
    #pragma once
    s替换我的include卫士。然后我再次关闭并重新打开文件,它为我解决了问题。是的,正如Kash在上面提到的,这可以解决问题。