MATLAB C++ Math Library
  Go to function:
    Search    Help Desk 
mwVarargout Class

Constructing an mwVarargout Object

MATLAB C++ Math Library functions that produce a variable number of outputs have an mwVarargout parameter as their last output argument.

In order to retrieve the varargout outputs from the function, you need to construct an mwVarargout object. You pass the variables to which the outputs will be assigned to the mwVarargout constructor and then pass the mwVarargout object as the last output argument to the function.

The arguments to the mwVarargout constructor differ from normal output arguments in two ways. When constructing an mwVarargout object:

For example, this code demonstrates a call to the M-function size, which takes a variable number of output arguments and a single input argument. The prototype for size() in C++ specifies an mwVarargout object, as its first parameter, and one or two input arguments. The call to size() in C++ corresponds to the call in M.

M code:

C++ prototype:

C++ call:

Note that the function size() takes no other required output arguments besides a varargout argument. It is called a "pure" varargout function. In pure varargout functions, the return value of the function is the same as the value assigned to the first element of the mwVarargout object, in this case the variable x. When calling a pure varargout function, you do not need to assign the output of the function to the first output argument explicitly; simply pass it to the mwVarargout constructor. For all functions in the math library, if the first argument is mwVarargout, the function is pure varargout.

If other output arguments precede the mwVarargout parameter, then the return value is not part of the mwVarargout object and must be explicitly assigned to a return value.



[ Previous | Help Desk | Next ]