While trying to understand the functionality of the unique_ptr, I wrote following program
1#include <memory>
2
3int main(int argc, char *argv[])
4{
5 int i;
6
7 std::unique_ptr<int> a(&i);
8 std::unique_ptr<int> c(a.get());
9
10 return 0;
11}
When I run this program through gdb I noticed that after "return 0" instruction at line no 10, gdb again goes back to execute line no. 8 instruction.
$ gdb ./unptr
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
(gdb) b main
Breakpoint 1 at 0x400686: file unptr.cpp, line 4.
(gdb) run
Starting program: /home/sbahir/work/funstuff/cplusplus/unptr
Breakpoint 1, main (argc=1, argv=0x7fffffffdae8) at unptr.cpp:4
4 {
(gdb) n
7 std::unique_ptr<int> a(&i);
(gdb) n
8 std::unique_ptr<int> c(a.get());
(gdb) n
10 return 0;
(gdb) n
8 std::unique_ptr<int> c(a.get());
(gdb) p a
$1 = std::unique_ptr<int> containing 0x7fffffffd9cc
(gdb) p c
$2 = std::unique_ptr<int> containing 0x7fffffffd9cc
(gdb)
I am not able to understand why this is happening. It would be great if someone could please explain or point to some reference to the material.
Thanks
Aucun commentaire:
Enregistrer un commentaire