Chapter Contents |
Previous |
Next |
Object Class: _cast |
Syntax | |
Details |
Syntax |
return = objectName._cast( arg1 ); |
Argument | Type | Use | Description |
---|---|---|---|
return | Object | Return | |
arg1 | Character | Input |
Details |
Because variables of a given class type X can contain instances whose class type is a subclass of X, the _cast method is needed to access the properties of such instances. For example, if you want to access methods that exist on a subclass, you would cast the variable containing the parent to the subclass:
/*Define box class */ box.scl class box; endclass /* Define redbox class with an additional method */ redbox.scl class redbox; rbmethod: method; put 'A method from a redbox'; endmethod; endclass; /* An SCL entry casting a variable of type box */ /* as a redbox, and then calling the redbox method */ X.scl init: dcl box b = _new_ redbox(); dcl redbox rb; rb = b.cast('work.a.redbox'); rb.rbmethod(); return;
The X.scl entry will perform the cast and print 'A method from a redbox'. A failed cast will result in a program halt.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.