I created a NULL
pointer of class App, but somehow the method of the NULL
object(of App) is working. Here is my code:
#include "App.h"
#include <iostream>
using namespace std;
int main()
{
App* pointer = NULL;
pointer->print();
system("pause");
}
Attached the Header file
#pragma once
#include <iostream>
using namespace std;
class App
{
private:
int x;
int y;
public:
App(void);
~App(void);
App(int a, int b)
{
x=a;
y=b;
}
void print()
{
cout<<"hello world"<<endl;
}
};
The running result an the screen in : hello world
. Why is that?