0

I have those two classes that include each other like this:

//A.hpp

#include "B.hpp"

class B;

class A {
   class AException : public std::exception {
      const char *what() const throw ();
   };
   // Some other members in which I use B class
};
//B.hpp

#include "A.hpp"

class A;

class B {
   typedef A::AException AException;
   // Some other members in which I use A class
};

So I want to bring A::AException into the scope of B, so that I have B::AException == A::AException, but the typedef is throwing incomplete type named in nested name specifier at compilation. I can't figure out how to do this, is this even possible ? I tried using the typename keyword but it doesn't work since there is no template. Thanks for the help (I use C++98 standard for this project)

Evg
  • 25,259
  • 5
  • 41
  • 83
Fayeure
  • 1,181
  • 9
  • 21
  • Why do you `#include "B.hpp"` into `A.hpp`? Do you really need this inclusion? – Evg Jan 26 '22 at 09:46
  • Circular dependency in code means that code is wrong - to much entangled. Best cure is break cycle (for example by introducing third class which both `A` and `B` depend on). Linked answer just hides more general problem. [See explanation](https://stackoverflow.com/q/1356304/1387438). – Marek R Jan 26 '22 at 09:51
  • @ChrisMM Not really, since it doesn't answer the `typedef` problem, unless it's possible to declare a class `typedef` under the class – Fayeure Jan 26 '22 at 09:52
  • Just move `AException` into its own header file then both 'A' and 'B' can just include that header – Alan Birtles Jan 26 '22 at 10:18

0 Answers0