Passing by reference does not change the variable

前端 未结 2 1469
旧巷少年郎
旧巷少年郎 2020-12-22 01:12

I am trying to implement a function to change state of the menu, but my reference is lost when it leaves the function:

void gotoLowerlevel(Menu *item)
{
             


        
2条回答
  •  难免孤独
    2020-12-22 01:43

    You're passing the pointer by value.

    Operations on the object it points to will be visible to the outside, but the pointer itself is only a copy.

    You might want to use a pointer to pointer.

提交回复
热议问题