gpt4 book ai didi

c++ - 为什么我的派生类 (Stock) 会报错?

转载 作者:行者123 更新时间:2023-11-28 05:40:06 27 4
gpt4 key购买 nike

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class Product
{
string title;
string sirName;
string isbn;
double wholesalePrice;
public:
Product();
Product(string, string, string, double);
~Product() {}
void setInfo(string, string, string, double);
string getTitle();
string getSurName();
string getIsbn();
double getWholesalePrice();

};


//Derived Class----------------------------Stock----------------------------
class Stock::public Product{

double retailPrice;
char bookFormat;
int stockLevel;

Stock();
~Stock() {}
void setRetail()
};

所以基本上我派生的 Stock 类不会工作...变量 double retailPrice 也不会工作,要么说不允许使用类型名称...

最佳答案

语法错误

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class Product
{
string title;
string sirName;
string isbn;
double wholesalePrice;
public:
Product();
Product(string, string, string, double);
~Product() {}
void setInfo(string, string, string, double);
string getTitle();
string getSurName();
string getIsbn();
double getWholesalePrice();

};


//Derived Class----------------------------Stock----------------------------
class Stock:public Product{ // use ':' instead of '::'

double retailPrice;
char bookFormat;
int stockLevel;

Stock();
~Stock() {}
void setRetail() {} // add function body or ';'
};

关于c++ - 为什么我的派生类 (Stock) 会报错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37299777/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com