Jump to content

SomNewNoInit: Difference between revisions

From EDM2
Created page with "{{DISPLAYTITLE:somNewNoInit}} This method creates a new instance of a class. For backward compatibility, this method does not take an Environment parameter. ; Original Class..."
 
Ak120 (talk | contribs)
mNo edit summary
 
Line 9: Line 9:


==Parameters==
==Parameters==
; receiver (SOMClass) : A pointer to the class object that is to create a new instance.
;receiver (SOMClass) : A pointer to the class object that is to create a new instance.


==Return Code==
==Return Code==
; rc (SOMObject) : A pointer to the newly created SOMObject object, or NULL.
;rc (SOMObject) : A pointer to the newly created SOMObject object, or NULL.


==Remarks==
==Remarks==
Line 42: Line 42:


==Related==
==Related==
===Methods===
;Methods
* [[somRenew]]
* [[somRenew]]


[[Category:SOMClass]]
[[Category:SOMClass]]

Latest revision as of 09:50, 5 April 2025

This method creates a new instance of a class.

For backward compatibility, this method does not take an Environment parameter.

Original Class
SOMClass

Syntax

SOMObject somNewNoInit (SOMClass receiver)

Parameters

receiver (SOMClass)
A pointer to the class object that is to create a new instance.

Return Code

rc (SOMObject)
A pointer to the newly created SOMObject object, or NULL.

Remarks

The somNew and somNewNoInit methods create a new instance of the receiving class. Space is allocated as necessary to hold the new object.

When either of these methods is applied to a class, the result is a new instance of that class. If the receiver class is SOMClass or a class derived from SOMClass, the new object will be a class object; otherwise, the new object will not be a class object. The somNew method invokes the somDefaultInit method on the newly created object. The somNewNoInit method does not.

Either method can fail to allocate enough memory to hold a new object and, if so, NULL is returned.

The SOM Compiler generates convenience macros for creating instances of each class, for use by C and C++ programmers. These macros can be used in place of this method.

Example Code

#include <animal.h>

void main()
{    Animal myAnimal;
/*------------------------------------------
Note:  next 2 lines are functionally equivalent to
         myAnimal = AnimalNew();
----------------------------------------- */
    /* Create class object: */
    AnimalNewClass(Animal_MajorVersion, AnimalMinorVersion);
    myAnimal = _somNew(_Animal);  /* Create instance of Animal cls */
    /* ... */
    _somFree(myAnimal);       /* Free instance of Animal */
 }

Related

Methods