Main Content

matlab.engine.typedinterface.generateCPP

Generate C++ code interface for MATLAB packages, classes, and functions

    Description

    example

    matlab.engine.typedinterface.generateCPP(headerFile,Name=Value) creates a C++ headerFile from one or more MATLAB® packages, classes, and functions. You must specify at least one Packages, Classes, or Functions name-value argument. Use the headerFile to build a C++ engine application. For more information, see Write MATLAB Code for Strongly Typed Interface.

    Examples

    collapse all

    Create a C++ header file myPkg.hpp from MATLAB classes Position and Rectangle in a shapes package.

    Create a package named shapes on the MATLAB path.

    Create a package file Position.m with these statements.

    classdef Position
        properties
            X   (1,1) double {mustBeReal}
            Y   (1,1) double {mustBeReal}
        end
    end

    Create a package file Rectangle.m with these statements.

    classdef Rectangle
        properties
            UpperLeft  (1,1) shapes.Position
            LowerRight (1,1) shapes.Position
        end
    
        methods
            function R = enlarge(R, n)
                arguments
                    R (1,1) shapes.Rectangle
                    n (1,1) double {mustBeReal}
                end
    
                % code
            end
    
            function R = show(R)
                arguments
                    R (1,1) shapes.Rectangle
                end
    
                % code
                disp("Upper left position (" + R.UpperLeft.X + "," + R.UpperLeft.Y + ")");
                disp("Lower right position (" + R.LowerRight.X + "," + R.LowerRight.Y + ")");
            end
        end
    end

    Generate the C++ interface header file myPkg.hpp.

    matlab.engine.typedinterface.generateCPP("myPkg.hpp",Packages="shapes")
    2 class(es) and 0 function(s) written to myPkg.hpp

    Use header file myPkg.hpp to build a C++ engine application.

    Input Arguments

    collapse all

    C++ header file created by the function, specified as a string or a character vector.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: Classes=["Position","Rectangle"],DisplayReport=true,SaveReport="report.log"

    Note

    You must specify at least one Packages, Classes, or Functions name-value argument.

    MATLAB packages to include in the C++ code interface, specified as a string array.

    Example: Packages="shapes"

    MATLAB classes to include in the C++ code interface, specified as a string array. The function supports user-authored classes and classes inherited from other user-authored classes.

    Example: Classes=["Position","Rectangle"]

    MATLAB functions to include in the C++ code interface, specified as a string array. The function supports user-authored functions.

    Example: Functions=["show","enlarge"]

    Option to display generation messages, specified as a numeric or logical 1 (true) or 0 (false).

    Log file name, specified as a string scalar. The name can include a relative or absolute path. The option creates a text file, so you can specify an appropriate file extension, but that is not required. The file contains detailed information about the matlab.engine.typedinterface.generateCPP function call and the generated structures.

    Example: SaveReport="report.log"

    Version History

    Introduced in R2022a