Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. const std = @import("std");
  2.  
  3. const FirstStruct = struct {
  4. number: u8,
  5.  
  6. fn createSecondStruct(self: FirstStruct) SecondStruct {
  7. return SecondStruct {
  8. .someFunction = self.someFunctionImplementation
  9. };
  10. }
  11.  
  12. fn someFunctionImplementation(self: FirstStruct) void {
  13. std.debug.warn("My number is: {}\n", self.number);
  14. }
  15. };
  16.  
  17. const SecondStruct = struct {
  18. someFunction: fn(self: FirstStruct) void
  19. };
  20.  
  21. pub fn main() void {
  22. const first = FirstStruct { .number = 42 };
  23. const second = first.createSecondStruct();
  24.  
  25. // Here I want to actually call the specific someFunctionImplementation
  26. // of my first struct
  27. second.someFunction();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement