Awkward C++ null pointer usage

I have found similar code to this on Elance, during a C++ test.
This amuse me a bit as I found it quite awkward.
This code below is from this question on StackOverflow


#include <iostream>

struct foo
{
    void bar() { std::cout << "gman was here" << std::endl; }
    void baz() { x = 5; }

    int x;
};

int main()
{
    foo* f = 0;

    f->bar(); // (a)
    f->baz(); // (b)
}

This entry was posted in programming and tagged . Bookmark the permalink.

Leave a comment