superdjo Posted March 17, 2023 Share Posted March 17, 2023 Hey everyone, I'm having a hard time trying to pass a struct to another struct as reference. All I can seem to be doing is a straight up copy. I know passing variables to methods or functions in vex are references but as soon as they get assigned they are copied into the new variable. Here is a brief example of what I'm talking about. struct test_1{ int a = 123; void print(){ printf("test_1 a value : %f\n",a); } } struct test_2{ test_1 t; void print(){ printf("test_2 a value : %f\n",t.a); } } cvex test(){ test_1 t1 = test_1(); test_2 t2 = test_2(t1); t1.a = 456; t1->print(); t2->print(); } The output will be test_1 a value : 456 test_2 a value : 123 I would expect it to be 456 for both if they are passed as reference. I've tried passing the struct in a method instead of the implicit constructor and same result. struct test_1 gets copied into the t variable of struct test_2 I basically have a few objects/structs referencing a main config/parameter struct. but when any one of these structs updates the config it doesn't get updated in the other structs. I basically need to go and reassign the struct to all other objects/struct again..... Is there no other way ? also I have many of these objects reading the main struct and it seems like a waste of memory to have to copy the struct over and over into each object/structs. Any help here would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.