-5

Can a class have a property and the class of the property is the class itself?

@interface testClass:NSObject
@property (nonatomic, strong) testClass *testProperty;
@end

@implementation testClass
@end
Xavjer
  • 8,838
  • 2
  • 22
  • 42
Hancock_Xu
  • 63
  • 5

1 Answers1

0

Yes it can have, this is called self-referencing class.

Why it is not a compiler issue ?

Because you create a pointer to the object of same type, not the object.

This is frequently seen in C / C++ data structures like Linked List.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140