令牌之前的预期主表达式'*'

expected primary-expression before '*' token

本文关键字:表达式 令牌      更新时间:2023-10-16

我的代码中出现以下错误:

C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h||In constructor 'deathBlock::deathBlock(GLuint*, float, float, float, float, float, float, float, float)':|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before '*' token|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before ',' token|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected primary-expression before 'float'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|9|error: expected '{' at end of input|
C:UsersSamuelDesktopTransferprojectstestMy_GamesrcdeathBlock.cpp|3|error: redefinition of 'deathBlock::deathBlock(GLuint*, float, float, float, float, float, float, float, float)'|
C:UsersSamuelDesktopTransferprojectstestMy_Gamesrc..includedeathBlock.h|8|error: 'deathBlock::deathBlock(GLuint*, float, float, float, float, float, float, float, float)' previously defined here|
||=== Build finished: 13 errors, 0 warnings (0 minutes, 0 seconds) ===|

我正试图让一个子类在创建时运行一个超类构造函数,我的代码如下:

超类构造函数:

Block::Block (GLuint *Tex, float x, float y,float texx,float texy,float texw,float texh,float w,float h) {
    tex = Tex;
    Setmx (x);
    setsxw(w);
    setsyw(h);
    tx=texx;
    ty=texy;
    tw=texw+tx;
    th=texh+ty;
    Setmy (y);
    setsx (x + Getxoffset() );
    setsy (y+Getyoffset());
}

和超类标题:

#ifndef BLOCK_H
#define BLOCK_H
#include "../include/MapObject.h"
#include <GL/glfw.h>
class Block: public MapObject {
public:
    Block(GLuint *, float x, float y,float,float,float,float,float,float);
    virtual ~Block();
    void render();
    virtual void onIntersect();
protected:
private:
    float tx,ty,tw,th;
    GLuint * tex;
};
#endif // BLOCK_H

子类构造函数:

deathBlock::deathBlock(GLuint *Tex, float x, float y,float texx,float texy,float texw,float texh,float w,float h)
:Block(GLuint *Tex, float x, float y,float texx,float texy,float texw,float texh,float w,float h);
{
    //ctor
}

子类标题:

#ifndef DEATHBLOCK_H
#define DEATHBLOCK_H
#include <GL/glfw.h>
#include "../include/Block.h"
class deathBlock:public Block
{
    public:
        deathBlock(GLuint *Tex, float x, float y,float texx,float texy,float texw,float texh,float w,float h);
        virtual ~deathBlock();
    protected:
    private:
};
#endif // DEATHBLOCK_H

另外,有人能告诉我一种使用搜索引擎搜索特殊字符的方法吗?这是因为我尝试过的所有方法都不允许这样做,这使得查找相关信息变得极其困难。

编辑:

这真是太愚蠢了,因为我刚刚将构造函数的参数直接复制到初始值设定项中,导致了我的错误。

GLunit#include <GL/gl.h>中定义。在尝试使用类型之前,您需要包含该标头。

更具体地说,由于您使用的是glfw.h,请检查您的定义,以确保包含gl.h(例如,未定义GLFW_INCLUDE_NONE),从而引入typedef