有没有办法不创建多个带参数的纯虚函数?

问题描述 投票:0回答:0

我看到这段代码

class Book {

public:

      //Provide:

      // - a pure virtual function to set the ISBN/eISBN

virtual void set(const int _eISBN) = 0;
virtual void set(const int _isbn) = 0;

is there any other wa to make this easier like 


      // - a pure virtual function to get the ISBN/eISBN
};

class ebook : public Book
{

      int eISBN;

public:

      void set(const int _eISBN) { eISBN = _eISBN; };

      int get() const { return eISBN; };

};

class paperbook : public Book

{
      int isbn;

public:

      void set(const int _isbn) { isbn = _isbn };

      int get() const { return isbn; };

};

有没有办法不让 2 个虚函数像它那样只要它是 int 就可以接受任何参数?

甚至它传递的任何参数

c++ function virtual
© www.soinside.com 2019 - 2024. All rights reserved.