-1

Is this declaration correct in c++?

class Abc
{
struct xyz x;

};

struct xyz
{
Abc abc;
int instances;
};

I receive the following error. error: field 'x' has incomplete type

So, if I have usecase as above, how do I create it?

nandini
  • 428
  • 2
  • 9
  • 20

1 Answers1

1

You cannot achieve this because there is a cyclic dependency between the two types. You can achieve this by using pointer to structure as member and forward declarations.

Community
  • 1
  • 1
Alok Save
  • 202,538
  • 53
  • 430
  • 533