C++ Object references in loop cycle

后端 未结 3 341
清歌不尽
清歌不尽 2021-01-27 11:49

I\'m trying to create different objects of the same type using a loop, and then storing a pointer to each specific object in a linked list. The problem is, each time an object i

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 12:21

    cout<<&user<
    
    

    should be:

    cout<
    
    

    &user is address of local variable Utilizador*, which remains the same. user variable value itself is the pointer you need, and it should be different on every iteration.

提交回复
热议问题