Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const std = @import("std");
- const FirstStruct = struct {
- number: u8,
- fn createSecondStruct(self: FirstStruct) SecondStruct {
- return SecondStruct {
- .someFunction = self.someFunctionImplementation
- };
- }
- fn someFunctionImplementation(self: FirstStruct) void {
- std.debug.warn("My number is: {}\n", self.number);
- }
- };
- const SecondStruct = struct {
- someFunction: fn(self: FirstStruct) void
- };
- pub fn main() void {
- const first = FirstStruct { .number = 42 };
- const second = first.createSecondStruct();
- // Here I want to actually call the specific someFunctionImplementation
- // of my first struct
- second.someFunction();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement