CArray:new
The new method creates an instance of the CArray 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.
A = CArray:new()
A = CArray:new( CArray2 )
A = CArray:new( n, val )
The following example shows the default constructor and destructor pair:
|
-- create a new instance of A of the CArray class. |
|
-- other uses of the class go here, between new and delete. |
|
-- deletes the object and its associated memory. |
The next example shows the use of all 3 constructors: default, copy, and initialization:
|
-- initialization constructor |
|
-- modify the value of A at index 3 |
|
-- copy constructor |
|
-- default constructor |
|
-- define B indices 1, 2, 3 |
|
-- shows Copy constructor |
|
-- result: AdotB = 12 |