Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // ------------ this is the struct, notice it has a Color struct member that has RGB members
  2. const Color = @import("color.zig").Color;
  3.  
  4. pub const Point = struct {
  5. x: f32,
  6. y: f32,
  7.  
  8. color:*Color,
  9.  
  10.  
  11. pub fn init(x:f32,y:f32, c: *Color) Point {
  12. return Point {
  13. .x=x,
  14. .y=y,
  15. .color=c,
  16. };
  17. }
  18. };
  19.  
  20.  
  21. // ------------ If I create a point like this, my concern is that this is the equivalent of handing out a local pointers.
  22. // ultimately I would prefer the Color member be a value, but it seems to me that I cannot do that and
  23. // it also seems to me that I MUST use a pointer, which implies that I MUST use explicit allocation.
  24. // Is this correct, or am I missing something?
  25. //
  26. var p = Point.init(3,4,&Color.init(0,0,0));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement