您好,我是C ++的新手,我正在尝试制作一个包含Application类对象的程序。
应用程序类应继承两个类。类Games和类desktopApp。 构建程序时,出现两个跟随错误:
没有匹配的函数来调用'desktop App :: desktop App()
没有匹配的函数来调用'Games :: Games()
我的问题是:
为什么会出现这些错误?
我怎样才能每次都想创建一个对象的父类的构造函数?
我是否需要为Application类中的每个父类都构造两个构造函数?
非常感谢你。
游戏类代码:
class Games
{
string category;
float price;
public:
Games (string category, float price)
{
this->category = category;
this->price = price;
}
};
desktopApp类代码:
class desktopApp
{
string edition;
vector<string> ratings;
public:
desktopApp (string edition, vector<string> ratings)
{
this->edition = edition;
copy(this->ratings.begin(), this->ratings.end(), back_inserter(ratings));
}
};
应用程序类代码:
class Application:public desktopApp, public Games
{
string name;
public:
Application (string name, string category, float price):Games (category, price)
{
this->name = name;
}
Application (string name, string edition, vector<string> ratings):desktopApp (edition, ratings)
{
this->name = name;
}
};
主要:
int main()
{
Applications game1("aGame", "Violent", 45.7);
}
Having two base classes
A
andB
, a classC
that inherits from both, looks like this:So in your case your
Application
should looks like this: