0

I often declares classes in other classes. Code:

class Human {
public:

  class Hand;
  class Foot;

  // ...
};

class Human::Hand {
public:
  // ...
};

class Human::Foot {
public:
  // ...
};

But if Human has Hand object(not pointer), then I get

error C2079: 'Human::hand' uses undefined class 'Human::Hand'

How can I solve it? Or maybe you know a better way to classify classes?

cogp
  • 5
  • 1
  • 4
    You cannot without fully defining the nested class in that case. Since the compiler needs to know the size of that object when generating code. Now, if you were using a pointer or reference, then it would behave like a forward definition and you can move the nested classes outside. – Tanveer Badar Apr 03 '20 at 13:56
  • @TanveerBadar ↓↓↓↓↓ – Asteroids With Wings Apr 03 '20 at 14:20
  • Yes, as @TanveerBadar mentioned, you cannot use a [Incomplete type](https://en.cppreference.com/w/cpp/language/type#Incomplete_type) here. – con ko Apr 03 '20 at 14:21

0 Answers0