开发者

C++ Error: expected primary expression before '*' token in constructor with parameters

I'm trying to make a class that has a constructor with five parameters. The only thing the constructor does is pass all the parameters to the superclass constructor. This class doesn't have any extra variables: its only purpose is to change the implementation of the getClassType virtual function. For some reason, this header gives an "expected primary expression before '*' token" on line with the constructor, and it also gives four "expected primary expression before 'int'" on the same line:

#ifndef SUELO_H
#define SUELO_H

#include "plataforma.h"
#include "enums.h"
#include "object.h"
#include "Box2D/Box2D.h"


class Suelo : public Plataforma
{
public:
    Suel开发者_开发知识库o(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

I assume these errors are caused by some typo, but I've checked on tutorials and on Google and I don't notice any mistake, so I'm stuck.


You don't pass the types into the base class constructor:

class A
{
    public:
    A(int) {};
}

class B : public A
{
public:
    B(int x) : A(x)  // notice A(x), not A(int x)
    {}
};

So, you constructor should look like this:

Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(world,x,y,w,h){}


You should not repeat the type for the super class constructor call.

Suelo(b2World *world,int x,int y,int w,int h) : Plataforma(world, x, y, w, h){}    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜