Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Nuthing is impossible !!Even a null pointer can access member functions

Nuthing is impossible !!Even a null pointer can access member functions

Scheduled Pinned Locked Moved IT & Infrastructure
csharpc++visual-studiolearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhishek Srivastava
    wrote on last edited by
    #1

    HI All ,:) I am a VC++ programmer,and some time My Acumen ask Microsofts VC++ (Visual Studio VC++ 6.0 )complier to complile my senseless programs ! :) See what I have asked this time to compile !!.. This is console based program, in which i am trying to call Member function of My class With a NULL pointer . And it is working fine....:cool: Please some one explain this to me ....is this happening of coz Compiler is fed up with my programs !! :-D #include "stdafx.h" #include class A { public : int var; A() { cout<<"In Consrtuctor !!"; } ~A() { cout<<"\nClass destroyed !!\n"; } void EvenNullPointerCanCallme(int a); }; void A::EvenNullPointerCanCallme(int a) { int *aa=new int[100]; cout<<"\nHow is that possible !!\n"; delete []aa; } int main(int argc, char* argv[]) { A *nullPtr=NULL;//see i made it NULL nullPtr->EvenNullPointerCanCallme(2);//How daring i am :) delete nullPtr;//I cannot call destructor ! return 0; } Are member functions statically linked with the Object name !! Actually i never found any concept of accessing Class member function with NULL pointers in Any of C++ books Which I have read (Plz let me know if u people have found it in any book !). I am grateful to all u peoples who had a look at my program !! Now see i am getting famous or what :) Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

    P 1 Reply Last reply
    0
    • A Abhishek Srivastava

      HI All ,:) I am a VC++ programmer,and some time My Acumen ask Microsofts VC++ (Visual Studio VC++ 6.0 )complier to complile my senseless programs ! :) See what I have asked this time to compile !!.. This is console based program, in which i am trying to call Member function of My class With a NULL pointer . And it is working fine....:cool: Please some one explain this to me ....is this happening of coz Compiler is fed up with my programs !! :-D #include "stdafx.h" #include class A { public : int var; A() { cout<<"In Consrtuctor !!"; } ~A() { cout<<"\nClass destroyed !!\n"; } void EvenNullPointerCanCallme(int a); }; void A::EvenNullPointerCanCallme(int a) { int *aa=new int[100]; cout<<"\nHow is that possible !!\n"; delete []aa; } int main(int argc, char* argv[]) { A *nullPtr=NULL;//see i made it NULL nullPtr->EvenNullPointerCanCallme(2);//How daring i am :) delete nullPtr;//I cannot call destructor ! return 0; } Are member functions statically linked with the Object name !! Actually i never found any concept of accessing Class member function with NULL pointers in Any of C++ books Which I have read (Plz let me know if u people have found it in any book !). I am grateful to all u peoples who had a look at my program !! Now see i am getting famous or what :) Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

      P Offline
      P Offline
      Peter Weyzen
      wrote on last edited by
      #2

      It works because: * you are not accessing member data (not using 'this') * non-virtual functions are staticly linked by name Make the function virtual, it should fail then. Functions that are in your class but do not access member data, should be marked as static. It'll work the same. And at that point you can access it with: A::EvenNullPointerCanCallme() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [Santa Cruz Networks](http://www.santacruznetworks.com)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups