Main Content


Determine if C++ object is null

Since R2019b



tf = clibIsNull(cppObj) returns logical 1 (true) if cppObj is nullptr. Otherwise, it returns logical 0 (false).


collapse all

Suppose that you create an interface to library nullptr, built from this nullptr.hpp header file, containing a function that returns NULL.

class A {
    double val;

// Function returning nullptr object
A* returnObjectNullptr() {
    return nullptr;

Display nullptr for an object of class A. The MATLAB® code is used as an illustration and does not execute as is, unless you build the interface.

ret = clib.nullptr.returnObjectNullptr
ret = 
    null A

Test for nullptr.

if clibIsNull(ret) 
% Code to process nullptr

Input Arguments

collapse all

C++ object created in MATLAB, specified as a handle

Version History

Introduced in R2019b