Mag*_*nus 3 c++ constructor compiler-errors
我正在尝试创建一个具有五个参数的构造函数的类.构造函数唯一能做的就是将所有参数传递给超类构造函数.这个类没有任何额外的变量:它的唯一目的是改变getClassType虚函数的实现.由于某种原因,这个头文件在构造函数的行上提供了"'''token之前的预期主表达式",并且它在同一行上还提供了四个"'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
Run Code Online (Sandbox Code Playgroud)
我认为这些错误是由一些错误造成的,但我已经检查了教程和谷歌,我没有注意到任何错误,所以我被卡住了.
Cha*_*had 10
您不会将类型传递给基类构造函数:
class A
{
public:
A(int) {};
}
class B : public A
{
public:
B(int x) : A(x) // notice A(x), not A(int x)
{}
};
Run Code Online (Sandbox Code Playgroud)
所以,你的构造函数应该如下所示:
Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(world,x,y,w,h){}
Run Code Online (Sandbox Code Playgroud)