Is using NULL references OK?

前端 未结 7 1392
一整个雨季
一整个雨季 2020-12-05 20:37

I came across this code:

void f(const std::string &s);

And then a call:

f( *((std::string*)NULL) );

A

相关标签:
7条回答
  • 2020-12-05 21:15

    for the case you can make "empty object", which will play the role of the zero pointer

    class Foo
    {
    static Foo empty;
    public:
      static bool isEmpty( const Foo& ref )
      {
        return &ref==∅
      }
    }
    
    0 讨论(0)
提交回复
热议问题