Main Content

Limitations to C/C++ Support

You can create a MATLAB® interface to 64-bit compiled libraries based on C++98 and commonly occurring C++11 features. However, if a library contains the following data types or language features, then the functionality is not included in the MATLAB interface to the library. You might be able to include this functionality by creating a wrapper header file. For more information, see C++ Limitation Workaround Examples.

Data Types Not Supported

  • Any type with a size greater than 64 bits, for example long double

  • References to a pointer, for example int*&

  • Pointers or arrays of std::string

  • Pointers or references to enumerations

  • Vectors of pointers to class objects, for example std::vector<Myclass*>

  • Reference data members

  • void* data members

  • Multidimensional data member arrays

  • Modifying static data members

  • ** pointers, except:

    • MATLAB supports char** types.

    • MATLAB supports ** pointers to custom classes used as function or ​method parameter types.

    • MATLAB supports void** used as function or method parameter types.

  • Multilevel pointers, such as type***

  • C function pointers and std::function as function return types or data members. You also cannot pass a MATLAB function as input to C function pointers or std::function parameter.

  • Class templates with incomplete or no instantiations

  • union

  • Types defined in the std namespace, except these supported types:

    • std::string

    • std::wstring

    • std::u16string

    • std::u32string

    • std::vector

    • std::shared_ptr

    • std::function

    • std::complex

Messages About Unsupported Types

If a library uses these data types, then the functionality is not included in the MATLAB interface to the library, and MATLAB displays messages like:

Did not add member 'methodName' to class 'ClassName' at HeaderFile.h:290.
  'long double' is not a supported type.

To view these messages, use the Verbose option in the clibgen.generateLibraryDefinition or clibgen.buildInterface functions.

Language Features Not Supported

  • move constructor

  • C++ operator overload

  • Unnamed namespaces and classes

  • Preprocessor directives (macros)

  • Global variables

  • Variadic functions

  • Function templates with incomplete or no instantiations

  • Creating objects of classes in std namespace, including custom classes.

  • Smart pointer semantics. Only std::shared_ptr is supported. MATLAB does not support operator overloads, move semantics, and the member functions in the class definition of the smart pointer which might restrict their effectiveness. Instead, a std::shared_ptr<T> behaves as type T in MATLAB. Type T can be passed as input for std::shared_ptr<T>, and type T is received as output for std::shared_ptr<T>.

  • Namespace aliases. Use original namespace name instead.

When you build a library containing these features or usage, MATLAB displays:

Warning: Some C++ language constructs in the header file are not supported and not imported.


Saving C++ objects into a MAT-file is not supported.

Inheriting C++ class in MATLAB

MATLAB does not support creating MATLAB classes that inherit a C++ interface class.

Unsupported Class Methods

MATLAB does not support implementing operators by defining these associated functions.


Method to Define

a(s1,...,sn) = bsubsassign(a,s,b)

Related Topics