Bull DPX/20 Podręcznik Użytkownika Strona 168

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 424
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 167
1-156 SOMobjects Base Toolkit: Programmers Reference Manual
C Example
Following is the implementation for a class Animal that introduces an attribute sound of type
string and overrides somInit and somUninit, along with a main program that creates and
then frees an instance of class Animal:
#define Animal_Class_Source
#include <animal.ih>
#include <string.h>
SOM_Scope void SOMLINK somInit (Animal somSelf)
{
AnimalData *somThis = AnimalGetData (somSelf);
Environment *ev = somGetGlobalEnvironment();
Animal_parents_somInit (somSelf);
if (!__get_sound(somSelf, ev)) {
__set_sound(somSelf, ev, SOMMalloc(100));
strcpy (__get_sound(somSelf, ev), ”Unknown Noise”);
somPrintf (”New Animal Initialized\n”);
}
}
SOM_Scope void SOMLINK somUninit (Animal somSelf)
{
AnimalData *somThis = AnimalGetData (somSelf);
Environment *ev = somGetGlobalEnvironment();
if (__get_sound(somSelf, ev)) {
SOMFree(__get_sound(somSelf, ev);
__set_sound(somSelf, ev, (char*)0);
somPrintf (”Animal Uninitialized\n”);
Animal_parents_somUninit (somSelf);
}
}
/* main program */
#include <animal.h>
void main()
{
Animal myAnimal;
myAnimal = AnimalNew ();
_somFree (myAnimal);
}
/*
Program output:
New Animal Initialized
Animal Uninitialized
*/
Original Class
SOMObject
Related Information
Methods: somInit, somNew, somRenew
Przeglądanie stron 167
1 2 ... 163 164 165 166 167 168 169 170 171 172 173 ... 423 424

Komentarze do niniejszej Instrukcji

Brak uwag