Is it bad practice for a child object to have a pointer to its parent?

前端 未结 7 1751
我寻月下人不归
我寻月下人不归 2020-12-20 12:27

In a C++ application, let\'s say I have a window class, which has several instances of a control class. If my window wanted to notify a control that it had been clicked, I m

7条回答
  •  Happy的楠姐
    2020-12-20 13:08

    That's fine. It's a common pattern in UI frameworks. E.g., the .NET Windows Forms Control class has a constructor for specifying the parent (http://msdn.microsoft.com/en-us/library/wawy06xc.aspx).

提交回复
热议问题