As I understand it, structs are value types. Trying to define a recursive struct, even using optionals is effectively defining an infinitely large object.
You wouldn't expect this to work in C would you:
struct BinaryTree
{
struct BinaryTree left;
struct BinaryTree right;
};
You need to use references, which means in Swift, you need to use a class not a struct.
class Foo<T: Comparable>
{
var left: Foo<T>?
var right: Foo<T>?
var value: T?
init(left: Foo<T>?, right: Foo<T>?, value: T?)
{
self.left = left
self.right = right
self.value = value
> --
> You received this message because you are subscribed to the Google Groups "Swift Language" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
swift-languag...@googlegroups.com.
> To post to this group, send email to
swift-l...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/swift-language/03fa9f58-7d39-4033-9f54-86a633756832%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.