C# null coalescing operator equivalent for c++

前端 未结 7 1651
走了就别回头了
走了就别回头了 2020-12-09 16:02

Is there a C++ equivalent for C# null coalescing operator? I am doing too many null checks in my code. So was looking for a way to reduce the amount of null code.

7条回答
  •  星月不相逢
    2020-12-09 16:59

    I just found this: The ?? operator aka the Null Coalescing Operator

    You also have it in C/C++ as a GNU extension using the ?: operator :

    string pageTitle = getTitle() ?: "Default Title";
    

提交回复
热议问题