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. General Programming
  3. C / C++ / MFC
  4. Is there a NULL for member pointers?

Is there a NULL for member pointers?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugging
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.
  • M Offline
    M Offline
    Malcolm McMahon
    wrote on last edited by
    #1

    I had a go at writing a class that takes an optional member pointer as an argument. It's along the lines of class AttributeInt { char * CXMLNode::*m_units; ... public: AttributeInt (... , char * CXMLNode::*units = NULL) : .. ,m_units(units) According to the debugger this sticks 0xffffffff into the member if no parameter is given (I'd expected 0, but I suppose it's conceivable 0 might be a valid offset). The question is, how do I test for this, preferably in a portable way. I've tried m_units == NULL (never succeeds) m_units == (char * CXMLNode::*)-lL (won't compile)

    T 1 Reply Last reply
    0
    • M Malcolm McMahon

      I had a go at writing a class that takes an optional member pointer as an argument. It's along the lines of class AttributeInt { char * CXMLNode::*m_units; ... public: AttributeInt (... , char * CXMLNode::*units = NULL) : .. ,m_units(units) According to the debugger this sticks 0xffffffff into the member if no parameter is given (I'd expected 0, but I suppose it's conceivable 0 might be a valid offset). The question is, how do I test for this, preferably in a portable way. I've tried m_units == NULL (never succeeds) m_units == (char * CXMLNode::*)-lL (won't compile)

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      This works for me (VC6 SP5). Pointer to member representation set to "Best case always" in Settings/C++/C++ language.

      class CXMLNode
      {
      public:
      char *p1;
      char *p2;
      };

      class AttributeInt
      {
      char * CXMLNode::*m_units;
      public:
      AttributeInt(char * CXMLNode::*units = NULL) : m_units(units) {}

      void test()
      {
      	if (m\_units == NULL)
      	{
      		printf("m\_units is NULL\\n");
      	}
      	else
      	{
      		printf("m\_units is not NULL\\n");
      	}
      }
      

      };

      void main( void )
      {
      AttributeInt a;
      a.test();

      AttributeInt b(&CXMLNode::p1);
      b.test();
      

      }

      Tomasz Sowinski -- http://www.shooltz.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