CSet:new


The new method creates an instance of the CSet 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

S = CSet:new()

S = CSet:new( CSet2 )

where

    If no argument is passed, a new, empty CSet object is created.

    CSet2 is an existing CSet object whose members are copied.

    S is a new CSet object returned. On failure, nil is returned.

Example

The following example shows the use of a default constructor and destructor pair:

S = CSet:new()

-- create a new instance of S of the CSet class.

  --

-- other uses of the class go here

S:delete()

-- deletes the object and its associated memory.

The next example shows the use of both types of constructors:

S = CSet:new()

-- initialization constructor

S:Add( "Add" )

-- add a member

S:Add( "Mul" )

-- add a member

S:Add( "Div" )

-- add a member

Printf("Count= %d", S:Count())

-- result: Count = 3

S2 = CSet:new(S)

-- copy constructor

Printf("Count= %d", S2:Count())

-- result: Count = 3

Related Topics

Copy

delete

CSet class