C++ 错误:在带有参数的构造函数中'*'令牌之前预期的主表达式
C++ Error: expected primary expression before '*' token in constructor with parameters
我正在尝试创建一个具有五个参数的构造函数的类。构造函数所做的唯一一件事就是将所有参数传递给超类构造函数。这个类没有任何额外的变量:它的唯一目的是更改getClassType虚函数的实现。由于某种原因,该头文件在构造函数中提供了"在'*'标记之前的预期主表达式",并且在同一行中还提供了四个"在'int'之前的预期主表达式":
#ifndef SUELO_H
#define SUELO_H
#include "plataforma.h"
#include "enums.h"
#include "object.h"
#include "Box2D/Box2D.h"
class Suelo : public Plataforma
{
public:
Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(b2World* world,int x,int y,int w,int h){}
virtual ~Suelo();
virtual ClassType getClassType();
protected:
private:
};
#endif // SUELO_H
我认为这些错误是由一些打字错误引起的,但我已经检查了教程和谷歌,我没有注意到任何错误,所以我卡住了
不能将类型传递给基类构造函数:
class A
{
public:
A(int) {};
}
class B : public A
{
public:
B(int x) : A(x) // notice A(x), not A(int x)
{}
};
那么,你的构造函数应该是这样的:
Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(world,x,y,w,h){}
您不应该为超类构造函数调用重复类型。
Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(world, x, y, w, h){}
相关文章:
- holeMenuProgram.cpp:38:1 错误:'}'令牌之前的预期主表达式
- (错误:令牌之前'<<'预期的主表达式)
- 错误:C++中']'令牌之前的预期主表达式
- 错误:令牌之前的预期主表达式'&&'
- 令牌之前']'预期的主表达式?
- 错误:令牌之前的预期主表达式'/'
- 正则表达式使用提升令牌迭代器在单引号和括号之间提取值
- 令牌之前')'预期的主表达式(需要"template"消除歧义器)
- 错误:令牌之前的预期主表达式'<':Arduino RGB 舞灯
- 令牌之前出现错误')'主表达式
- C++错误:错误:令牌之前的预期主表达式'||'
- 令牌问题之前'*'预期的主表达式
- 令牌之前的预期表达式']'?C
- 退出状态 1 令牌之前的预期主表达式'.'
- C++错误:";"之前应为主表达式使用Cmake的令牌
- 向量空Push_back在令牌之前调用'{'预期的主表达式
- 令牌调用之前'...'预期的主表达式 模板化类的模板化方法
- 错误 预期主表达式在 ';" 之前令牌 C++
- 令牌之前的预期主表达式'-'
- 令牌之前的预期主表达式'<'