2
votes

So I have a class and a derived class. Both need to have constructors but the problem is I get errors for the derived class' constructor.

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 ;
}

In constructor 'Property::Property(int, std::string, SpaceType, std::string, int, int, PropertyCategory)':|

error: expected primary-expression before 'int'|

error: expected primary-expression before 'name'|

error: expected primary-expression before 'type'|

error: expected primary-expression before 'actionText'|

1
Youre not supposed to repeat the type names when calling parent constructor - Borgleader
The parent class is Space. I'll edit the code. - nikos kone
I know that. That's why I said you shouldnt specify parameter types when calling it's constructor... - Borgleader

1 Answers

1
votes

Just call superclass constructor with parameters:

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 ;
}