Why is there an implicit type conversion from pointers to bool in C++?

后端 未结 3 581
清酒与你
清酒与你 2020-11-30 13:28

Consider the class foo with two constructors defined like this:

class foo
{
public:
    foo(const std::string& filename) {std::cout <<         


        
3条回答
  •  佛祖请我去吃肉
    2020-11-30 14:06

    It's very common in C to write this

    void f(T* ptr) {
        if (ptr) {
            // ptr is not NULL
        }
    }
    

    You should make a const char* constructor.

提交回复
热议问题