Created
September 16, 2019 07:42
-
-
Save ul/8dc892c1fe37c4889bbde8526200ce15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem; | |
fn LinkedList(comptime T: type) type { | |
const Self = struct { | |
const Node = struct { | |
next: ?*Node, | |
data: T, | |
}; | |
first: ?*Node, | |
allocator: *mem.Allocator, | |
pub fn init(allocator: *mem.Allocator) !*Self { | |
var self = try allocator.create(Self); | |
self.first = null; | |
self.allocator = allocator; | |
return self; | |
} | |
}; | |
return Self; | |
} | |
test "LinkedList" { | |
var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); | |
defer arena.deinit(); | |
const allocator = &arena.allocator; | |
var list = try LinkedList(i32).init(allocator); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list.zig:14:50: error: use of undeclared identifier 'Self' | |
list.zig:32:35: note: referenced here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do it this way, you need to return the struct expression instead.