I am writing some Python code where I have to use parent-child design like this:
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"""
But Python raises a NameError
and complains that the Child
class was not defined. This is logical because it is under the Parent
class.
Is there something like "Forward declaration" in C++ to handle problems like this or is there is some other way? I tried to Google it with no success.