A Jazzy NULL, and ctors for Anonymous Classes
Hi
Consider the following implementation of a Jazzed up NULL ,as Meyers calls it,
from Effective C++, SE, Page 112.
#include <iostream>
#ifdef NULL
#undef NULL
#endif
//const
class // an anonymous class
{
public:
//any type of NULL non-member pointer
template <class T> operator T* () const //conversion operator
{
return 0;
}
//any type of NULL member pointer
template <class C, class T> operator T C::*() const
{
return 0;
}
private:
void operator &() const; //the address cannot be taken
Quote:
} NULL;
void x(char * s)
{
if (s) cout << s;
return;
Quote:
}
int main()
{
x(NULL);
int * xx;
if (xx == NULL)
cout << "NULL";
else
cout << "Not NULL";
cout << endl;
return 0;
Quote:
}
The problem is if i uncomment the const from the class defintion, my g++
[gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)], gives the following
error
uninitialized const `NULL'
What does this mean?
Also another related question. Can anonymous classes have ctors !
Ragnar
Capital Kernel Engineering
www.capitalos.4t.com