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

标签 c++ constructor compiler-errors

我正在尝试创建一个具有带五个参数的构造函数的类。构造函数唯一做的就是将所有参数传递给父类(super class)构造函数。这个类没有任何额外的变量:它的唯一目的是改变 getClassType 虚函数的实现。出于某种原因,此 header 与构造函数一起给出了“'*'标记之前的预期主表达式”,并且还在同一行上给出了四个“'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

我假设这些错误是由某些拼写错误引起的,但我已经检查了教程和 Google,但没有发现任何错误,所以我被卡住了。

最佳答案

您不将类型传递给基类构造函数:

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){}

关于C++ 错误 : expected primary expression before '*' token in constructor with parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6638666/

相关文章:

c++ - 如何计算复杂矩阵的指数?

c++ - C++中如何调用指针成员变量的构造?

c++ - 编译C++程序: “error: cast from ‘double*’ to ‘int’ loses precision”时出错

class - 无法解决 Eiffel 中的错误 “target of assigner call has no associated assigner command”

c++ - 遍历动态分配的矩阵

c++ - 在 64 位字上进行 32 位比较和交换

java - 构建我的 Java Swing 应用程序。 IE。何时何地使用类和不使用类

c# - 为什么我会收到 "inaccessible due to protection level"错误?

compiler-errors - 为什么这个最小的 Jack (nand2tetris) 程序不能编译?

c++ - std::set 及其 front_insert_iterator