【发布时间】:2017-02-07 19:31:10
【问题描述】:
发生了什么事。我已经查看了有关堆栈溢出的其他解决方案,但从我所看到的情况来看似乎没有。我有一个带有更改基本属性值的方法的基本对象。当我在子类(继承)中调用基函数时,我发现子类没有属性“baseAttribute”
class GameObject(object):
#This is the base class for gameObjects
def __init__(self):
self.components = {}
def addComponent(self, comp):
self.components[0] = comp #ignore the index. Placed 0 just for illustration
class Circle(GameObject):
#circle game object
def __init__(self):
super(GameObject,self).__init__()
#PROBLEM STATEMENT
self.addComponent(AComponentObject())
#or super(GameObject,self).addComponent(self,AComponentObject())
#or GameObject.addComponent(self, AComponentObject())
编辑: 抱歉,我最初从未通过自我。
【问题讨论】:
标签: python python-2.7 oop inheritance