I have multiple classes that inherit from one base class, and each class is in a separate header. I want the user to be able to include just the base class header, but that would require me to include the other derived classes in the base header, which would lead to some sort of circular dependency, and I’ve read somewhere that circular dependency is a bad thing.
My class is a socket class, and the derived classes are socket_udp, socket_tcp, socket_raw, and so on.
How do I solve the circular dependency? Maybe the class design is bad, and I don’t need different classes for different socket types? I’m a bit confused here.
Thanks!
One option would be to create a new header file that includes all of the header files for the derived and base objects. Just including that single header would therefore include all the other header files. If you order the includes in this file so that you never include a class without first including all its parent classes, you can avoid circular dependencies.