Imagine the next problem. I want a class Map. Every Map instances contains a list of Locations. I also want that every Location knows of the Map that owns him. (Could this hinder encapsulation?) In Python I can use type hints, with no problem. I can define both classes in either order.
from __future__ import annotations
class Map:
def __init__(self):
self.locations: list[Location]
self.locations = []
class Location(self, ):
def __init__(self, owner: Map):
self.owner = owner
This hinders encapsulation, I guess. But in Python, aren't we all adults according to the philosophy of the language? This helps me a lot. If the Location child can access the parent, I can change something in the Location and the Parent can know.
Can I use this kind of design in C++? It this recommended? Can a child have a reference of his father? Can I declare a child class with knowledge of its parent AT THE SAME TIME that the parent know of its children?
I've learned C++ by myself and I never read about it.