Writing a Factory Design Pattern Program with separate Header Files and Class Implementations
-
Hi, I am trying to learn factory design pattern in c++, writing a program with separate header files and their class implementations in .cpp files. But i am facing problem. I was trying the ShapeFactory from where we implement Circle and Rectangle. invalid new-expression of abstract class type 'Circle' invalid new-expression of abstract class type 'Rectangle' But i am getting these errors and also few other errors. Can someone please help on this. Regards Litu
-
Hi, I am trying to learn factory design pattern in c++, writing a program with separate header files and their class implementations in .cpp files. But i am facing problem. I was trying the ShapeFactory from where we implement Circle and Rectangle. invalid new-expression of abstract class type 'Circle' invalid new-expression of abstract class type 'Rectangle' But i am getting these errors and also few other errors. Can someone please help on this. Regards Litu
"new" ... you can't instantiate an "abstract" class; you need to subclass it first or use an existing derived class.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Hi, I am trying to learn factory design pattern in c++, writing a program with separate header files and their class implementations in .cpp files. But i am facing problem. I was trying the ShapeFactory from where we implement Circle and Rectangle. invalid new-expression of abstract class type 'Circle' invalid new-expression of abstract class type 'Rectangle' But i am getting these errors and also few other errors. Can someone please help on this. Regards Litu
Your Shape class should be the only abstract one. Circle and Rectangle should be complete classes that inherit Shape. There is a very good set of articles on factory patterns by @SneshPrajapati here on CodeProject, starting with Factory Patterns - Simple Factory Pattern[^].