0

Circular dependency and incomplete type

Hi I have a class object constructed from one class's method. New class need to have reference of its caller class as it want to access other method. How to achieve this as I had tried with forward declaration, but can't still call the method due to incomplete type error. Please suggest. Refer code for more details and feel free to ask for any further questions. Basically, I need to call test method of controller from table class method. https://sololearn.com/compiler-playground/ckCWuRLzKMCA/?ref=app

19th Jun 2024, 3:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
5 Respuestas
+ 2
Hi Ketan, This is also new for me, but I just found this on SO and looks like it's something similar to what you are trying to do. https://stackoverflow.com/questions/19962812/error-member-access-into-incomplete-type-forward-declaration-of
19th Jun 2024, 4:28 PM
Ipang
+ 1
Perfect Ipang . Thanks a lot for this pointer. It solved my concern. https://sololearn.com/compiler-playground/c4z6UH4zvGjn/?ref=app
19th Jun 2024, 4:40 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Definitely Bob_Li , circular reference is always a bad sign. But unfortunately, everything is not in our control in a large code base and restructure is not approved for a small bug in real world. so, to find out the alternative solution highlighting code smell is the only option we have at the moment. thanks for sharing ūüĎć about code issue.
20th Jun 2024, 4:48 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Hey ūüĎč I've heard that c++ could be useful in making video games and hardware systems, but i see from peoples works that c++ isn't that good, all i've seen were very simple and i'm confused . Shall keep learning it or pass to another language. I hope you tell me anything could help
20th Jun 2024, 4:18 PM
Karim Bousmaha
Karim Bousmaha - avatar
0
codes like these feels like the start of spaghetti code... If two classes are tightly coupled, why not just combine it into a single class? Just because you can make it work doesn't mean you should. Maybe it's an indication that the code needs to be refactored.
20th Jun 2024, 3:00 AM
Bob_Li
Bob_Li - avatar