为什么我的派生类(股票)会出错?

时间:2016-05-18 12:33:14

标签: c++

#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也不会说不允许输入类型名称...

1 个答案:

答案 0 :(得分:1)

您有一些语法错误

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