Factory Design and Inheritance

  access-modifiers, c++, factory-pattern, inheritance, oop

I’m making a project for my college in which I am implementing factory design but the problem is i cant return the address of object it gives an error conversion "C++ conversion to inaccessible base class is not allowed".

#include<iostream>

using namespace std;

class card
{
    protected:
       int fee;
       int limit;

    public:
       virtual void setvar() = 0;
};

class silver : card
{
    void setvar()
     {
        fee = 500;
        limit = 10000;
     }
};

class gold : card
{
    void setvar()
      {
         fee = 1000;
         limit = 20000;
      }
};

class platinum : card
{
    void setvar()
     {
        fee = 2000;
        limit = 40000;
     }
};

Error is given here on the return lines of this class FactoryDesign.

class factorydesign
{
    private :
        factorydesign();
    public:
        static card* getcard(int c)
         {
             if (c == 0)
              {
                return new silver();
              }
             else if (c == 1)
              {
                return new gold();
              }
             else if (c == 2)
              {
                return new platinum();
              }
         }

 };
 int main()
 {
      int choice;

      cout << "0 : Silver cardn1 : Golden Cardn2 : Platinum card n";
      cin >> choice;

      card* obj;
      obj = factorydesign::getcard(choice);

      return 0;
 }

Can anybody please also give a detailed explanation of why it is happening because?

Source: Windows Questions C++

LEAVE A COMMENT