我做了一项研究,但解决方案与我的程序不匹配。从大代码我只采取了错误的部分。请建议。
#include <iostream>
using namespace std;
class Products {
static Products* prod;
public:
//Creat a static funtion which does the task what client was doing
static void checkStockStatus(int choice)
{
switch (choice) {
case 1:
prod = new Mobile();
break;
}
prod->inStockStatus();
}
virtual void inStockStatus() = 0;
};
class Mobile : public Products {
public:
void inStockStatus()
{
cout << "Mobiles are instock" << endl;
}
};
int main()
{
int choice = 1;
Products::checkStockStatus(choice);
return 0;
}
输出: 在静态成员函数'static void Products :: checkStockStatus(int)'中: 14:29:错误:'Mobile'之前的预期类型说明符