Hi Everyone,I am not sure, but compiler passes
I have the following program,
class A{
private:
int a;
public :
void func1();
};
void A::func1(){
cout <<"hello world";
}
int main(){
A *a1=NULL;
a1->func1();
return 0;
}
And it prints hello world. I think it is undefined behavior but i'm
assuming that the memory for the function is allocated as the compiler
parses through the class definition and hence there should be a way to
access the memory (function)... Is there any legal way without
creating an object of the class?
Thanks in advance ! ! !
func1(this);
In your case this == NULL. However since func1(...) is not accessing
'this', so things worked.
I do not think such type of code will work, if you are accessing class
bound memory.
With Regards,
Reetesh Mukul