Main Content

findConstructor

R2026b

Find constructor in C++ class

Since R2026b

    Description

    ctorDef = findConstructor(classDef,CPPInputTypeNames=typeNames) finds a constructor in the class that matches the specified name with the specified input type list and returns a clibgen.api.ConstructorDefinition object for the matching constructor. If the function does not find a match, it returns an empty ConstructorDefinition object.

    example

    Examples

    collapse all

    Find incomplete constructors in the Shape class.

    Configure the interface for a library defined by shapelib.hpp and create an interface definition object.

    icfg = clibgen.api.InterfaceConfiguration("shapelib",HeaderFiles="shapelib.hpp");
    idef = clibgen.api.InterfaceDefinition(icfg);
    

    Display the constructors of the Shape class that require additional definition.

    classDef = idef.findClass("geometry::Shape");
    classDef.IncompleteConstructors
    ans = 
      ConstructorDefinition with properties:
    
        OwningClassName: "geometry::Shape"
           CPPSignature: "geometry::Shape::Shape(double * coords,int numPoints)"
        MATLABSignature: <Define incomplete inputs to see the MATLAB signature.>
              CPPInputs: [1×2 clibgen.api.InputArgumentDefinition]
                 Status: Incomplete
               Included: false
    
      Show all properties
    

    Use the CPPInputTypeNames argument to find a specific constructor.

    Using the shapelib interface, display information about the constructors.

    classDef = idef.findClass("geometry::Shape");
    classDef.Constructors
    ans = 
      1×4 ConstructorDefinition array with properties:
    
        OwningClassName
        CPPSignature
        MATLABSignature
        CPPInputs
        Status
        Included
    
      Display as table
    

    If there are multiple constructors, click the Display as table link.

                              CPPSignature                            Status      Included
        ________________________________________________________    __________    ________
    
        "geometry::Shape::Shape()"                                  Complete       true   
        "geometry::Shape::Shape(std::string const & name)"          Complete       true   
        "geometry::Shape::Shape(double * coords,int numPoints)"     Incomplete     false  
        "geometry::Shape::Shape(geometry::Shape const & input1)"    Complete       true   
    

    To choose the default constructor geometry::Shape::Shape(), which has no inputs, type:

    defaultCtor = classDef.findConstructor(CPPInputTypeNames=[])
    defaultCtor = 
    
      ConstructorDefinition with properties:
    
        OwningClassName: "geometry::Shape"
           CPPSignature: "geometry::Shape::Shape()"
        MATLABSignature: clib.shapelib.geometry.Shape/Shape()
              CPPInputs: [1×0 clibgen.api.InputArgumentDefinition]
                 Status: Complete
               Included: true

    Input Arguments

    collapse all

    Class definition, specified as a clibgen.api.ClassDefinition object.

    Fully qualified C++ input type names, specified as a string vector, used to disambiguate overloaded functions.

    Output Arguments

    collapse all

    Constructor definition, returned as a clibgen.api.ConstructorDefinition object.

    Version History

    Introduced in R2026b