【问题标题】:expected primary-expression before '*' token'*' 标记之前的预期主表达式
【发布时间】:2013-08-29 10:47:55
【问题描述】:

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

C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h||In constructor 'deathBlock::deathBlock(GLuint*, float, float, float, float, float, float, float, float)':|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before '*' token|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before ',' token|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected primary-expression before 'float'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.h|9|error: expected '{' at end of input|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\deathBlock.cpp|3|error: redefinition of 'deathBlock::deathBlock(GLuint*, float, float, float, float, float, float, float, float)'|
C:\Users\Samuel\Desktop\Transfer\projects\test\My_Game\src\..\include\deathBlock.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

另外有人可以指出我使用搜索引擎搜索特殊字符的方法吗?这是因为我尝试过的所有方法都不允许这样做,这使得找到相关信息非常困难。

编辑:

这对我来说太愚蠢了,因为我刚刚将构造函数的参数直接复制到了初始化程序中——导致了我的错误。

【问题讨论】:

  • 为什么在基类构造调用中有所有这些 type 声明?试试:Block(Tex, x, y, texx, texy, texw, texh, w, h)
  • 我正在尝试执行以下操作:stackoverflow.com/questions/120876/…
  • @WhozCraig 因为它们(在语法上)是非法的,因为这里只允许使用 表达式 [class.base.init]/1,这是 OP 正在寻找的错误.把它作为一个答案。
  • 剪切和粘贴的危险。
  • 还有一个你不想要的分号。

标签: c++ inheritance subclass superclass


【解决方案1】:

GLunit#include &lt;GL/gl.h&gt; 中定义。在尝试使用该类型之前,您需要包含该标题。

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

【讨论】:

猜你喜欢
  • 2013-02-23
  • 1970-01-01
  • 1970-01-01
  • 2017-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 2017-09-24
相关资源
最近更新 更多