How does the below program work in c++?
- by Srinivasa Varadan
I have just created 2 pointers which has undefined behavior and try to invoke a class member function which has no object created ?
I don't understand this?
#include<iostream>
using namespace std;
class Animal
{
public:
void talk()
{
cout<<"I am an animal"<<endl;
}
};
class Dog : public Animal
{
public:
void talk()
{
cout<<"bark"<<endl;
}
};
int main()
{
Animal * a;
Dog * d;
d->talk();
a->talk();
}