c++ - 播放器.cpp(6) : error C2143: syntax error : missing ';' before '.'

标签 c++ syntax

不知何故,我一直收到这个错误:

player.cpp(6):错误 C2143:语法错误:缺少“;”在“.”之前

这是头文件

    #ifndef Enemy
    #define Enemy
    #include "SDLGameObject.h"
    class Enemy : public SDLGameObject

    {
      public:
         Enemy(const LoaderParams* pParams): SDLGameObject(pParams) {}
         void draw();
         void update();
         void clean() {}
    };
    #endif

$这是 Enemy.cpp 文件:

    #include "Enemy.h"
    void Enemy::draw()
    {
       SDLGameObject.draw();
    }

    void Enemy::update()
    {
       m_x -= 1;
       m_currentFrame = int(((SDL_GetTicks() / 100) % 6));
    }

$这是 Enemy 的基类 SDGameObject.h

    #ifndef __SDLGameObject__
    #define __SDLGameObject__
    #include "GameObject.h"
    #include <string>

    class SDLGameObject : public GameObject
    {
      public:
         SDLGameObject(const LoaderParams* pParams);

         virtual void draw();

         virtual void update();
         virtual void clean();

      protected:
         int m_x;
         int m_y;

         int m_width;
         int m_height;

         int m_currentRow;
         int m_currentFrame;

         std::string m_textureID;
     };

     #endif

而GameObject.h只是SDLGGameObject.h的抽象基类

我不确定是否包含它,但似乎错误出在 Enemy.cpp 文件中。

非常感谢您的帮助,因为我是这方面的新手。谢谢大家:)))

最佳答案

一旦预处理器 完成其工作,编译器 将获取SDLGGameObject.h 的全部内容作为其输入,行

`class : public SDLGameObject`

之后是所有其他位。这是因为由于您的行 #define Enemy,预处理器已将 Enemy 替换为空白文本。这就是为什么您的编译器会发出某种虚假错误的原因。

补救,使用

#ifndef Enemy_h
#define Enemy_h

相反。

关于c++ - 播放器.cpp(6) : error C2143: syntax error : missing ';' before '.' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25141101/

相关文章:

javascript - 有什么方法可以使 javascript 中的嵌套回调代码更具可读性吗?

javascript - jqGrid 排序或搜索不适用于具有 json 点表示法的列

javascript - 使用这种语法的原因是什么 (0, _.Em)();

c++ - 从连续的固定大小的矩形制作更宽的矩形?

c++ - 按名称调用不同签名的方法

c++ - 访问子类 C++ 的属性/函数

syntax - Clojure — 英镑符号的含义?`

c++ - 在 OpenCV 中隐藏鼠标光标

C++ FMOD Studio 无法为 freq 的 FMOD DSP PARAMETER FFT 赋值。分析

javascript - 试图理解为什么调用末尾有额外的括号