0

I defined a class A and a class B like following:

class A
{
public:
    using Type = int;
    B::Type v;
};

class B
{
public:
    using Type = double;
    A::Type v;
};

And then I get a compile error

 error: 'B' does not name a type

The following codes don't work, either.

class B;

class A
{
public:
    friend class B; // makes no sense
    using Type = int;
    B::Type v;
};

class B
{
public:
    using Type = double;
    A::Type v;
};

You know, a class cannot be defined twice, so A must be defined after B, or B must be defined after A.

How can I use each other's member types?

Methods can be defined outside, but can member types be defined outside a class?

My only solution is to move the types out of the classes.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
aleck099
  • 428
  • 2
  • 10
  • 3
    You have a [circular dependency](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes) problem here. Do any of these solve your problem? I see you have tried one of them, I think. –  Nov 07 '19 at 04:39
  • You'll have to make at least one of those typedefs a non-member (or a member of yet third class that doesn't depend on `A` or `B`). – Igor Tandetnik Nov 07 '19 at 04:51
  • So the only way is not to use B::Type and redefine a new type not depending B, right? – aleck099 Nov 07 '19 at 11:43

0 Answers0