Hence this:
class A
{
public:
A()
{
cout << "A() ";
}
void f()
{
cout << "f ";
}
~A()
{
cout << "~A() ";
}
};
int main()
{
A *p = (A*)2;
p->f();
}
class A
{
public:
A()
{
cout << "A() ";
}
void f()
{
cout << "f ";
}
~A()
{
cout << "~A() ";
}
};
int main()
{
A *p = (A*)2;
p->f();
}
//ouput is
// f
How can a programm call a member function of non existing object? How the programm passes the this pointer to the function?