null pointer call in c++

 

#include <iostream>

class Foo 
{
    public:    
         static void bar() 
        {
            std::cout << "NULL->bar()" << std::endl;
        }
};    

int main(void) 
{
    Foo * foo = NULL;
    foo->bar(); //<=> Foo::bar();
    return 0; 
} 

 

空指針可以引用類的static函數,等價于classname::static_fun();。

 

posted on 2013-02-24 21:09  mhgu  阅读(141)  评论(0编辑  收藏  举报