【发布时间】:2019-09-23 03:53:57
【问题描述】:
我正在编写一些 Python 代码,我必须使用这样的父子设计:
from typing import List
class Parent(object):
def add_children(self, child: List[Child]):
"""Do something here"""
class Child(object):
def set_parent(self, parent: Parent):
"""Do something here"""
但是 Python 提出了一个 NameError 并抱怨 Child 类没有定义。这是合乎逻辑的,因为它属于Parent 类。
C++ 中是否有类似“前向声明”之类的东西来处理此类问题,还是有其他方法?我尝试谷歌搜索没有成功。
【问题讨论】:
标签: python parent-child typing