Trying to create c++ interface, testing now.
/*
* Simple interface tests
*/
#include <iostream>
using namespace std;
class Shape {
public:
virtual int area() = 0;
};
class Square: public Shape {
public:
int side;
int height;
Square (int a, int b){
side = a;
height = b;
}
~Square(){cout << "destructor" << endl;}
int area(){
return side * height;}
};
int main(int argc, char **argv){
{
Shape * s1 = new Square(2, 2);
cout << s1->area() << endl;
delete s1;
}
return 0;
}
Destructor seems not working and I'm deleting the pointer only. Is this a memory leak? If yes how to avoid it? Of course if I do:
Square s1(2,2);
Then is fine, but I'm not sure what's happening when creating pointer to the abstract Shape class.