Call C++ Class Methods Directly from a C Function Block - MATLAB & Simulink (original) (raw)

Main Content

This example shows how to use the C Function block to call C++ class methods. In this example, a C++ class and its methods are defined in adder_cpp.h and implemented in adder_cpp.cpp.

To run this example model, you must configure MATLABĀ® to use a C++ compiler. This can be done using the mex -setup C++ command, and selecting a C++ compiler.

To enable access to the C++ class from the C Function block, in the model, specify the header file and the source file in the Configuration Parameters > Simulation Target pane. In this model, the custom code header file adder_cpp.h declares an adder class along with the class methods.

In the Output Code section, the class method is called. In this example, the ports of the C Function block are configured as follows:

See Also

C Function

Topics