Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: nullptr  (Read 2960 times)

0 Members and 1 Guest are viewing this topic.

Badestrand

  • Newbie
  • *
  • Posts: 17
    • View Profile
nullptr
« on: August 18, 2008, 04:03:58 pm »
I'm sure you heard about C++0x, which comes along with a typesafe nullptr. In some open-std-proposal (Link), the typesafe nullptr to use in the current standard is introduced, take a look:
Code: [Select]

const    // this is a const object...
class {
public:
    template<class T>    // convertible to any type
    operator T*() const    // of null non-member
    { return 0; }    // pointer...

    template<class C, class T>  // or any type of null
    operator T C::*() const    // member pointer...
    { return 0; }

private:
    void operator&() const;    // whose address can't be taken
} nullptr = {};    // and whose name is nullptr

or, to save lines and chars:
Code: [Select]

const class {
public:
    template<class T> operator T*() const  {return 0;}
    template<class C, class T> operator T C::*() const  {return 0;}
private:
    void operator&() const;
} nullptr = {};


It's just a very practical thingy which solves the NULL-problematic:
Code: [Select]

void foo( int some_value );
void foo( int* some_pointer );

foo( 0 );       // calls foo(int)
foo( NULL );    // calls foo(int)
foo( nullptr ); // calls foo(int*)




I just wanted to tell you about it in case you didn't know and want to use it :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
nullptr
« Reply #1 on: August 18, 2008, 11:14:00 pm »
Interesting, thank you :)
Laurent Gomila - SFML developer