Quote:
|
#include <stdio.h> class A { public: void PrintMe(); }; void A::PrintMe() { printf("Hello World\n"); } void main() { A* p = 0; p->PrintMe(); // why not crash } |
![]() |
|
|||||||
![]() |
|
More
|
|
|
Bookmarks | Thread Tools | Search this Thread | Display Modes |
|
|
#1 | |
|
Go4Expert Member
Join Date: Sep 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Why the program not crash when access NULL object?Quote:
|
|
|
|
|
|
|
#2 |
|
Go4Expert Founder
![]() |
Re: Why the program not crash when access NULL object?
Because you compiler does find that function where p points.
|
|
|
|
|
|
#3 |
|
Team Leader
![]() Join Date: Dec 2006
Location: Texan now in Central NY
Posts: 835
Thanks: 0
Thanked 3 Times in 2 Posts
Rep Power: 4 ![]() |
Re: Why the program not crash when access NULL object?
Because your compiler is not standards compliant (neither is MS) in this respect. Your use of the return type, "void", for main is also non-compliant.
__________________
DaWei on Pointers Grumpy on C++ Exceptions Functionality rules; clarity matters. If you can work a little elegance in there, you're stylin'. |
|
|
|
|
|
#4 | |
|
Go4Expert Member
Join Date: Sep 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: Why the program not crash when access NULL object?Quote:
|
|
|
|
|
|
|
#5 | |
|
Go4Expert Founder
![]() |
Re: Why the program not crash when access NULL object?Quote:
|
|
|
|
|
![]() |
|
More
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| Bookmarks | |
|
|
|
|