How to resolve the algorithm Inheritance/Multiple step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Inheritance/Multiple step by step in the Nim programming language
Table of Contents
Problem Statement
Multiple inheritance allows to specify that one class is a subclass of several other classes. Some languages allow multiple inheritance for arbitrary classes, others restrict it to interfaces, some don't allow it at all.
Write two classes (or interfaces) Camera and MobilePhone, then write a class CameraPhone which is both a Camera and a MobilePhone. There is no need to implement any functions for those classes.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Inheritance/Multiple step by step in the Nim programming language
Source code in the nim programming language
type
Camera = ref object of RootObj
MobilePhone = ref object of RootObj
CameraPhone = object
camera: Camera
phone: MobilePhone
proc `is`(cp: CameraPhone, t: typedesc): bool =
for field in cp.fields():
if field of t:
return true
var cp: CameraPhone
echo(cp is Camera)
echo(cp is MobilePhone)
You may also check:How to resolve the algorithm Sudan function step by step in the Lua programming language
You may also check:How to resolve the algorithm Rendezvous step by step in the Tcl programming language
You may also check:How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Objeck programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the F# programming language