Reputation: 470
Here's an interesting one for the objective-C gurus out there...
Is there a way to declare an objective-C block typedef that contains an argument of that typedef?
typedef BOOL (^SSCellAction) ( UITableViewController* inTVC, SSCellAction inChainedAction );
The idea is that I wanted to used chained menu action system that allows a chain of work/response to occur (usually 1-3 items). When the last action invokes, it passes nil for inChainedAction
. Since this seems relatively trivial to imagine, I'll be dammed if I can't figure out how to declare it without llvm saying no. :)
Upvotes: 4
Views: 437
Reputation: 122429
rmaddy's comment is correct. Just as in C, a typedef
cannot use itself. Basically, a typedef
does not make a real type, but just makes an alias that the compiler expands out at compile-time. It is always possible to manually expand all typedef
s in your program yourself (which is sometimes an instructive exercise), so that your program is written without typedef
s. However, a recursive typedef
cannot be expanded.
Some possible workarounds:
id
as the parameter type, and cast back into the right type inside the block. This loses type safety.Upvotes: 2