Plange


convert the specified pointer from a type A, to a type B, if B inherits A. Otherwise, the result is a null pointer.

<Type> Mammal = class { };

<Type> Dog = type inheriting Mammal {
	<Void → Void> bark;
};

<Type> Cat = type inheriting Mammal {
	<Void → Void> meow;
};

<Mammal → Void> speak := (x) {
	Dog dog := dynamic_cast<Dog>(x);
	if (dog != null) {
		dog.bark();
	}
	Cat cat := dynamic_cast<Cat>(x);
	if (cat != null) {
		cat.meow();
	}
};
			

copyright © Brent Lewis 2017