-1
//abstract product
class AbstractProduct
{
public:
    virtual void diplay(void) = 0;
};
//concrete product
class Histogram : public AbstractProduct
{
public:
    Histogram()
    {
        cout << "default construct a Histogram!" << endl;
    }
    void display(void)
    {
        cout << "Display Histogram!" << endl;
    }
};
//factury class
class Factury
{
public:
    static AbstractProduct* getProduct(string type)
    {
        AbstractProduct* absP;
        if(type=="Histogram")
        {
            Histogram his;// error, Variable type "Histogram" is an abstract class   
        }
        return absP;
    }
};

I have already implement the pure virtual function, but it still said my derived class is an abstract class. I do not know why.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
user4185295
  • 17
  • 1
  • 1

2 Answers2

4

The problem is that these functions

virtual void diplay(void) = 0;

and

void display(void)
{
    cout << "Display Histogram!" << endl;
}

have different names. I think there is simply a typo.

Take into account that this static function

static AbstractProduct* getProduct(string type)
{
    AbstractProduct* absP;
    if(type=="Histogram")
    {
        Histogram his;// error, Variable type "Histogram" is an abstract class   
    }
    return absP;
}

also have no sense because it returns uninitialized pointer absP

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

If that really is your code you have a typo

 virtual void diplay(void) = 0;

and

 void display(void)
djna
  • 54,992
  • 14
  • 74
  • 117