A Jazzy NULL, and ctors for Anonymous Classes 
Author Message
 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



Tue, 13 Sep 2005 12:07:55 GMT  
 A Jazzy NULL, and ctors for Anonymous Classes

Quote:

> #include <iostream>

Please ask C++ questions elsewhere.  comp.lang.c++ may be a valid
choice.
--
"I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz


Tue, 13 Sep 2005 12:28:33 GMT  
 A Jazzy NULL, and ctors for Anonymous Classes

Quote:

> Hi
> Consider the following implementation of a Jazzed up NULL ,as Meyers calls it,
> from Effective C++, SE, Page 112.

> #include <iostream>

Who cares.  comp.lang.c++ is down the hall.  Turn on the light, so you
want trip on the obfuscation cluttering the floor.


Tue, 13 Sep 2005 12:33:57 GMT  
 A Jazzy NULL, and ctors for Anonymous Classes

Quote:

> Hi
> Consider the following implementation of a Jazzed up NULL ,as Meyers calls it,
> from Effective C++, SE, Page 112.

> #include <iostream>

Who cares.  comp.lang.c++ is down the hall.  Turn on the light, so you
won't trip on the obfuscation cluttering the floor.


Tue, 13 Sep 2005 12:34:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Class ctor for class with Main method

2. Linker error for .ctor and Finalize in managed classes

3. CoCreateInstance hangs in CTOR for session class.

4. template class with overloaded ctor...

5. nested classes and default ctor

6. CoCreateInstance hangs in ctor for session class

7. comparison class for std::priority_queue as a ctor arg

8. C# support for anonymous classes?

9. Anonymous inner classes

10. anonymous classes

11. Anonymous classes

12. Anonymous classes java - c#

 

 
Powered by phpBB® Forum Software