Tree in Swift programming language -
i tried make tree swift using fonctionnal way
here code:
//this code works struct testarbre { var racine: int? } let a0 = testarbre(racine:nil) //this code stuck on error struct arbre { var racine: int? var feuillegauche: arbre? var feuilledroite : arbre? } let a1 = arbre(racine: 10, feuillegauche: nil, feuilledroite: nil) let a2 = arbre(racine:5, feuillegauche:nil, feuilledroite:nil) let a3 = arbre(racine:1, feuillegauche: a1, feuilledroite: a2);
and here error when running code:
<unknown>:0: error: unable execute command: segmentation fault: 11 <unknown>:0: error: swift frontend command failed due signal (use -v see invocation) command /applications/xcode6-beta.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/swift failed exit code 254
structs value types. imagine how struct initialized: have struct arbre, system allocate memory members, int , struct arbre, system allocate memory members (an int , struct arbre), system allocate memory members (an int , struct arbre) . . . -> crash
you need make class.
if want struct containing reference same type done pointers in c.
why "typdef struct { struct s *s; } s;" containing pointer same type compile?
Comments
Post a Comment