CMatrixRow:Copy


The Copy method duplicates the current CMatrixRow and returns the new object.

Syntax

R = CMatrixRow:Copy()

where

    R is a new CMatrixRow containing the same values as the current one. In place of CMatrixRow, use the name of the actual object to be copied.

  

This method copies an existing CMatrixRow and returns a reference to the new CMatrixRow. You cannot copy a CMatrixRow or other class object using the trivial statement B = A, as this simply makes the value of B a reference to the object A. In other words, B becomes an alias to A. To get around this, two copy methods are provided by the CMatrixRow class:

To create a CMatrixRow that is a copy of the current object, use the Copy method. This creates a new CMatrixRow B before duplicating the values of the current object A. For example,

  B = A:Copy()

-- CMatrixRow A already exists

To create a new CMatrixRow that is a copy of an existing object, use the copy constructor, as in

  B = CMatrixRow:new(A)

-- CMatrixRow A already exists

Choose the syntax that fits best with your script.

Example

The following script duplicates the CMatrixRow R into a new CMatrixRow R2:

R = CMatrixRow:new()

-- create a CMatrixRow

R:Set( 1, 12.55 )

-- set member 1

R:Set( 40, -155.23 )

-- set member 40

R2 = R:Copy()

-- creates a duplicate CMatrixRow R2

Printf("N = %d", R2:Count() )

-- result: N = 2

Related Topics

new

CMatrixRow class