CMatrixRow:new


The new method creates an instance of the CMatrixRow class. This method returns to the caller a reference to the object it creates. The calling code must assign this reference to a name (see below). If the object cannot be created, nil is returned.

Note: This method's name uses all lower case to present it as the analog of the C++ new operator. Generally, the names of class methods begin with an uppercase letter but new and delete are different.

Syntax

R = CMatrixRow:new()

R = CMatrixRow:new( CMatrixRow2 )

R = CMatrixRow:new( n, val )

where

    Default constructor. The new CMatrixRow R has no elements. The name CMatrixRow must be used with a colon to specify the type of new object to be created.

    This is a copy constructor. The new CMatrixRow R is initialized to the properties of the CMatrixRow2 argument.

    The new CMatrixRow R is initialized with the first n elements having the same value, val.

    The parameter val is optional and may be any type of Lua value. If omitted, it defaults to 0.0.

Examples

The following example shows the default constructor and destructor pair:

A = CMatrixRow:new()

-- create a new instance of A of the CMatrixRow class.

  --

-- other uses of the class go here, between new and delete.

A:delete()

-- deletes the object and its associated memory.

The next example shows the use of all 3 constructors: default, copy, and initialization:

A1 = CMatrixRow:new( 5, 1.0 )

-- initialization constructor

A1[3] = 5

-- modify the value of A at index 3

A = CMatrixRow:new(A1)

-- copy constructor

B1 = CMatrixRow:new()

-- default constructor

B1:Init( 3, 2.0 )

-- define B indices 1, 2, 3

B = CMatrixRow:new(B1)

-- shows Copy constructor

Printf("AdotB = %lg", A:Dot(B) )

-- result: AdotB = 12

Related Topics

Copy

delete

CMatrixRow class