I’m trying to resolve the following in C++/CLI which creates a circular dependency. Meaning the way it compiles, the class does not exist yet when in EventHandler; but the class needs to create an EventHandler, and thus the order of classes cannot be reversed either.
I have reasons for both classes to have references to each other, but the compiler won’t recognize the classes. (i.e. compiler error).
You solve this the same way you would in ordinary C++: you first declare the type and its functions, then use them, and only define them after that, outside of the rest of the type’s code. So, if you want to have everything in one file (and not deal with header files etc.), you could do something like:
The normal C++ way is to declare all types and their functions in header files and put only their definitions into code files. Doing it this way is much easier for big projects, especially if you have circular dependencies.