【问题标题】:VS 2008 C++ error C2059 and C2238VS 2008 C++ 错误 C2059 和 C2238
【发布时间】:2011-05-22 06:19:58
【问题描述】:

我正在尝试移植在 linux/g++ 中开发的程序/游戏,以便它在 Windows 7 VS 2008 C++ 上运行。程序使用OpenGL、SDL、Boost等库。

我已经解决了很多错误,但我有点卡在这个错误上。

我收到错误代码 C2059 和 C2238。实际的错误信息是:

------ Build started: Project: Asteroid Blaster, Configuration: Release Win32 ------
Compiling...
WeaponDisplay.cpp
Weapon.cpp
ViewFrustum.cpp
Vector3D.cpp
UDP_Server.cpp
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(40) : error C2059: syntax error : ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(40) : error C2238: unexpected token(s) preceding ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(41) : error C2059: syntax error : ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(41) : error C2238: unexpected token(s) preceding ';'
UDP_Client.cpp
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(40) : error C2059: syntax error : ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(40) : error C2238: unexpected token(s) preceding ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(41) : error C2059: syntax error : ';'
d:\College\AsteroidBlaster\Utility/ViewFrustum.h(41) : error C2238: unexpected token(s) preceding ';'
TractorBeamShot.cpp

ViewFrustum.h 文件如下:

  /**
   * viewFrustum: It's got useful functions to cull items that aren't in your view frustum
   * 
   * 2-7-11
   * CPE ---
   */

  #ifndef __VIEW_FRUSTUM_H__
  #define __VIEW_FRUSTUM_H__

  #include "Items/Object3D.h"
  #include "Utility/Plane.h"
  #include "Utility/Matrix4.h"
  #include <vector>
  #include <set>

  class ViewFrustum {
     public:

        ViewFrustum();
        virtual ~ViewFrustum();

        /* Takes in a list of all the Object 3D's around, and culls them down to only the ones
         * that are inside the view frustum.
         */
        virtual std::list<Drawable*>* cullToViewFrustum(std::vector<Drawable*>* all, bool skipParticles);
        virtual std::list<Object3D*>* cullToViewFrustum(std::vector<Object3D*>* all);

        /* Prints out details about all of the planes of the view frustum.
         */
        virtual void print();

     private:
        Matrix4 projMatrix;
        Matrix4 modelViewMatrix;
        Plane* top;
        Plane* bottom;
        Plane* left;
        Plane* right;
        Plane* near;
        Plane* far;

        /** 
         * A modified version of chedDrawableOutside, used by the AI. This stops the
         * AI from targeting Drawable objects which are slightly outside the field
         * of view, which still need to be drawn.
         */
        bool checkTargetableOutside(Drawable* obj);

        /* Returns true if the Drawable object is completely outside of the 
         * view frustum planes.
         * Returns false if it's even part-way inside.
         */
        virtual bool checkDrawableOutside(Drawable* obj);
  };

  #endif 

违规行 (40-41) 是:

  Plane* near;
  Plane* far;

这有点令人困惑,因为 ViewFrustum obj 已经编译,但是当它到达 UDP_Server.cpp 和 UDP_Client.cpp 时,它会抛出一个错误。我不确定这是否重要,但 UDP 类使用 Boost 的 aiso 和序列化模块。我知道 Boost 有时会发出奇怪的警告,但我不确定 Boost 是否必须对这个错误做任何事情。

如果有人知道这是为什么,或者如果您需要发布更多代码,请告诉我。

【问题讨论】:

    标签: c++ visual-studio-2008 opengl boost sdl


    【解决方案1】:

    您可能会在该标题之前包含一个 Windows 标题,并且在其中定义了 nearfar。这些是 16 位时代的(遗留)事物。

    有关解决方法,请参阅此相关问题 Is there a clean way to prevent windows.h from creating a near & far macro?

    【讨论】:

    • 将变量名称更改为 *Plane(即 - nearPlane)修复了此错误。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多