I have two C++ header/source files. In Object.h
:
#include "Exception.h"
class SomeException : public Exception {};
class Object {
public:
someFoo() {
throw SomeException();
}
};
And in Exception.h
:
#include <exception>
#include "Object.h"
class Exception : public Object, public std::exception {
// ...
};
The "include once" macro is omitted. The code would not be compiled, because one of Object
or Exception
will become unknown, so I add a forward declaration header file common.h
:
class Object;
class Exception;
And change #include
lines to #include "common.h"
. This skill works for arguments' and returning types, but it fails on inheritance, because C++ refuses to derive an incomplete base class. How to solve it?