Created
April 10, 2015 11:21
-
-
Save hakanderyal/0c5a0c4b02b60c40dac1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
GenericSceneObj* = ref object | |
SceneNode* = ref object | |
children*: seq[SceneNode] | |
parent*: SceneNode | |
sceneObj*: GenericSceneObj | |
GameObj* = ref object | |
name: string | |
AnotherGameObj* = ref object | |
health: int | |
# I want to make GameObj and AnotherGameObj to be compatible with GenericSceneObj, | |
# so I can store them in SceneNode | |
# Is it possible without inheriting from GenericSceneObj? | |
# I've tried using user defined type classes, | |
# but couldn't get them to work (probably using them in a wrong way) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
GenericSceneObj* = concept x | |
draw(x) | |
SceneNode* = ref object | |
children*: seq[SceneNode] | |
parent*: SceneNode | |
sceneObj*: GenericSceneObj | |
proc newSceneNode* (sceneObj: GenericSceneObj): SceneNode = | |
result = SceneNode(sceneObj: sceneObj) | |
newSeq(result.children, 10) | |
proc attachChild* (this: SceneNode, child: SceneNode) = | |
child.parent = this | |
this.children.add(child) | |
# udtc_test.nim(16, 18) Error: invalid type: 'GenericSceneObj' in this context: 'proc (SceneNode, SceneNode)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment