SOM Kernel Reference 1-101
somNew, somNewNoInit Methods
Purpose
Creates a new instance of a class.
IDL Syntax
SOMObject somNew ( );
SOMObject somNewNoInit ( );
Note: For backward compatibility, these methods do not take an Environment parameter.
Description
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.
Parameters
receiver A pointer to the class object that is to create a new instance.
Return Value
A pointer to the newly created SOMObject object, or NULL.
Example
#include <animal.h>
void main()
{ Animal myAnimal;
/* -------------------------------------------------
: 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 */
}
Original Class
SOMClass
Related Information
Methods: somRenew
Kommentare zu diesen Handbüchern