在我的代码中有这样的东西:
shared_ptr<vector<unsigned int>> f =
make_shared<vector<unsigned int>>();
如何打印矢量,我只能使用
访问shared_ptr对象 frame variable f
和
frame variable f.__ptr_->size()
call to a function 'std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::size() const' that is not present in the target
出现此错误?
答案 0 :(得分:5)
鉴于此代码段:
#include <vector>
#include <memory>
using namespace std;
int main()
{
shared_ptr<vector<unsigned int> > f =
make_shared<vector<unsigned int> >();
f->push_back(1);
f->push_back(1);
f->push_back(1);
return 0;
}
LLDB对我有用:
(lldb) fr var
(std::__1::shared_ptr<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >) f = 0x00000001001038c8 size=3 (strong=1 weak=1) {
__ptr_ = 0x00000001001038c8 size=3
}
更好的是,如果我展开 _ _ptr _:
(lldb) fr var --ptr-depth=2
(std::__1::shared_ptr<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >) f = 0x00000001001038c8 size=3 (strong=1 weak=1) { __ptr_ = 0x00000001001038c8 size=3 {
[0] = 1
[1] = 1
[2] = 1 } }