c++在派生类构造函数中期望的主表达式

C++ expected primary expression before in derived class constructor

本文关键字:期望 表达式 构造函数 派生 c++      更新时间:2023-10-16

我知道很多这样的问题,但是没有一个能帮我解决我的问题。

这些是我的树中的构造函数。

Tree();
Tree(string name, int season, int lifeTime, int height, int leafType);

tree.cpp:

Tree::Tree() : Plant()
{
    this->lifeTime = 0;
    this->height = 0;
    this->leafType = -1;
}
Tree::Tree(string name, int season, int lifeTime, int height, int leafType) : Plant(string name, int season)
{
    this->lifeTime = lifeTime;
    this->height = height;
    this->leafType = leafType;
}

我得到expected primary-expression before name错误。怎么解呢?

Plant(string name, int season)需为Plant(name, season)。你正在调用一个没有声明的函数,所以你没有在函数调用中包含参数类型。