Jump to content

SomDescendedFrom: Difference between revisions

From EDM2
Created page with "{{DISPLAYTITLE:somDescendedFrom}} This method tests whether one class is derived from another. Not generally overridden. For backward compatibility, this method does not take..."
 
Ak120 (talk | contribs)
mNo edit summary
 
Line 4: Line 4:
For backward compatibility, this method does not take an Environment parameter.
For backward compatibility, this method does not take an Environment parameter.


; Original Class: [[SOMClass]]
;Original Class: [[SOMClass]]
 
==Syntax==
==Syntax==
  boolean somDescendedFrom (SOMClass receiver, SOMClass aClassObj)
  boolean somDescendedFrom (SOMClass receiver, SOMClass aClassObj)


==Parameters==
==Parameters==
; receiver (SOMClass) : A pointer to the class object to be tested.  
;receiver (SOMClass) : A pointer to the class object to be tested.
; aClassObj (SOMClass) : A pointer to the potential ancestor class.
;aClassObj (SOMClass) : A pointer to the potential ancestor class.


==Return Code==
==Return Code==
; rc (boolean) :  
;rc (boolean) :
* Returns 1 (true) if receiver is derived from aClassObj. 0
* Returns 1 (true) if receiver is derived from aClassObj.
* Returns 0 (false) if receiver is not derived from aClassObj.
* Returns 0 (false) if receiver is not derived from aClassObj.


Line 45: Line 46:
  Dog IS descended from Animal
  Dog IS descended from Animal
  Animal is NOT descended from Dog
  Animal is NOT descended from Dog


==Related==
==Related==
===Methods===
;Methods
* [[somIsA]]
* [[somIsA]]
* [[somIsInstanceOf]]  
* [[somIsInstanceOf]]


[[Category:SOMClassMgr]]
[[Category:SOMClassMgr]]

Latest revision as of 18:27, 12 October 2022

This method tests whether one class is derived from another. Not generally overridden.

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

Original Class
SOMClass

Syntax

boolean somDescendedFrom (SOMClass receiver, SOMClass aClassObj)

Parameters

receiver (SOMClass)
A pointer to the class object to be tested.
aClassObj (SOMClass)
A pointer to the potential ancestor class.

Return Code

rc (boolean)
  • Returns 1 (true) if receiver is derived from aClassObj.
  • Returns 0 (false) if receiver is not derived from aClassObj.

Remarks

This method tests whether the receiver class is derived from a given class. For programs that use classes as types, this method can be used to ascertain whether the type of one object is a subtype of another.

This method considers a class object to be descended from itself.

Example Code

#include <dog.h>
/* --------------------------------------------
   Note: Dog is a subclass of Animal.
   -------------------------------------------- */
main()
{
  AnimalNewClass(0,0);
  DogNewClass(0,0);

  if (_somDescendedFrom (_Dog, _Animal))
     somPrintf("Dog IS descended from Animal\n");
  else
      somPrintf("Dog is NOT descended from Animal\n");
  if (_somDescendedFrom (_Animal, _Dog))
     somPrintf("Animal IS descended from Dog\n");
  else
     somPrintf("Animal is NOT descended from Dog\n");

This program produces the following output:

Dog IS descended from Animal
Animal is NOT descended from Dog

Related

Methods