Reputation: 252
I'm creating a class named Circle
and needs a public property to access its 'parent' Circle
instance. Thus I code it like this:
class Circle {
public:
...
Circle parent;
...
}
But this gave me an error: Incomplete type is not allowed
What should I do?
Upvotes: 1
Views: 74
Reputation: 208446
That cannot be done. Consider what the memory footprint of your type would be: a Circle
contains a Circle
, so it size cannot be smaller than the inner Circle
, but that size is the same as the size of the outer Circle
, reaching a contradiction.
Maybe you meant to store a pointer or smart pointer? That is allowed, since the size of the pointer is known by the compiler.
Upvotes: 4