Is there a NULL for member pointers?
-
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) -
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)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