Consider following code,
class Interface
{
public:
Interface(){}
virtual ~Interface(){}
virtual void method1() = 0;
virtual void method2() = 0;
};
class Concrete : public Interface
{
private:
int myMember;
public:
Concrete(){}
~Concrete(){}
void method1();
void method2();
};
void Concrete::method1()
{
// Your implementation
}
void Concrete::method2()
{
// Your implementation
}
int main(void)
{
Interface *f = new Concrete();
f->method1();
f->method2();
delete f;
return 0;
}
The author used Interface *f = new Concrete();
to instantiate an abstract class in the main function and later he used delete f;
but the issue with new
and delete
is that I don't like them. Is there are an alternative way to instantiate this class?