I have the following code:
class A {
public:
virtual void f() {
cout << "1" << endl;
}
};
class B : public A {
public:
void f {
cout << "2" << endl;
}
};
int main() {
A* a = new B();
a->f();
return 0;
}
And my question is: why there is no need to to delete a before return of the main function? According to my understanding this code will result in a memory leak, am I wrong?
[UPDATE] I checked the following code using valgrind and it confused me even more. It says there is a memory leak.