Purpose | The deleteclass statement is used to delete class(es) from the run-time class memory. This has the effect of stripping behaviour from objects that were instantiated of the class. It is also a way of conserving class memory because you eliminate classes that are no longer needed. | |||
Format |
deleteclass {comma-separated list of classes};
{comma-separated list of classes} |
a comma-separated list of classes or an expression that yields such a list. |
|
|
Example #1 |
class XPlant { public: int GetAge() { return this.Age; }; int Age = 20; }; node(XPlant) MyTree; xout("MyTree is " + MyTree.GetAge() + " years old"); deleteclass "XPlant"; xout("\r\nMyTree is " + MyTree.GetAge() + " years old");
The GetAge method is first called when the XPlant class still exists in class memory. However, the second time it is called, the XPlant class has been deleted, in which case we get an error sent to the output stream. The text in the output stream is: |
|||
Example #2 |
class XPlant { public: int GetAge() { return this.Age; }; int Age = 20; }; node(XPlant) MyTree; xout("MyTree is " + MyTree.GetAge() + " years old"); deleteclass "XPlant"; xout("\r\nclass memory is\r\n" + classes);
This example is the same as the one above. The difference is that after the deleteclass statement we write the contents of class memory to the output stream: |