之前的预期主要表达式

expected primary-expression before ' '

本文关键字:表达式      更新时间:2023-10-16

所以我有一个类和一个派生类。两者都需要具有构造函数,但问题是我会因派生类构造函数而获得错误。

class Property : public Space
Property::Property(int id, string name, SpaceType type, string actionText, int buyCost, int upgradeCost, PropertyCategory category): Space(int id, string name, SpaceType type, string actionText)
{
    this->buyCost = buyCost ;
    this->upgradeCost = upgradeCost ;
    this->category = category ;
    numberOfHouses = 0 ;
}

在constructor'属性::属性(int,std :: string,spaceType,std :: string,int,int,property category(':|

错误:" int" |

之前的预期主要表达

错误:"名称" |

之前的预期主要表达

错误:"类型" |

之前的预期主要表达

错误:'actionText'|

之前的预期主要表达

只需用参数调用超类构造函数:

Property::Property(int id, string name, SpaceType type, string actionText, int 
buyCost, int upgradeCost, PropertyCategory category): Space(id, name,  type, actionText)
{
    this->buyCost = buyCost ;
    this->upgradeCost = upgradeCost ;
    this->category = category ;
    numberOfHouses = 0 ;
}