我有一个
std::set<MyIntrusivePtr<T> >
当我从gdb中打印出这个容器时,我得到了
(gdb) p m_sSymbol->m_sVariables
$10 = std::set with 1 element = {[0] = {m_p = 0x781a0630}}
(gdb)
m_p是普通指针
T* m_p;
包含在
中MyIntrusivePtr<T>
如何取消引用此指针?
示例会话:
[user@ hostname /directory]% cat tmp.cpp
#include <set>
struct A
{ int *m_p;
bool operator<(const A &_r) const
{ return m_p < _r.m_p;
}
A(int *p)
:m_p(p)
{
}
};
int main()
{ int a, b, c;
std::set<A> s{A(&a), A(&b), A(&c)};
}
[user@ hostname /directory]% g++ -g tmp.cpp -std=c++17 -fno-inline
[user@ hostname /directory]% ~/bin./gdb a.out
GNU gdb (GDB) 8.0
(gdb) b main
Breakpoint 2 at 0x400a45: file tmp.cpp, line 14.
(gdb) r
Starting program: /directory/a.out
Breakpoint 2, main () at tmp.cpp:14
14 std::set<A> s{A(&a), A(&b), A(&c)};
(gdb) n
15 }
(gdb) p s
$1 = std::set with 3 elements = {[0] = {m_p = 0x7fffffffd484}, [1] = {m_p = 0x7fffffffd488}, [2] = {m_p = 0x7fffffffd48c}}
(gdb) p s[0]
No symbol "operator[]" in current context.
(gdb) p (*s.begin())
Cannot evaluate function -- may be inlined
(gdb)