如何在矢量< unique_ptr>中打印出内容在Mac OS X上使用gdb [英] How to print out the content in vector<unique_ptr> with gdb on Mac OS X
问题描述
这是测试代码。
class A
{
int x;
public:
A(){}
〜A(){}
A(A& a){}
A(int x){this-> ; x = x;}
int get(){return x;}
};
int main()
{
vector< unique_ptr< A>> v;
auto a = new A(10);
unique_ptr< A> pa(a);
v.push_back(move(pa)); // move(pa); (auto& i:v)
{
cout<< i-> get();
}
}
它在g ++ 4.8下编译得很好,我可以调试它使用gdb。遵循)
我可以使用Xcode; lldb在Xcode上工作正常。
I'm trying to use C++11 feature on Mac OS X. I downloaded g++ 4.8.1 with port.
This is the test code.
class A
{
int x;
public:
A() {}
~A() {}
A(A& a) {}
A(int x) {this->x = x;}
int get() {return x;}
};
int main()
{
vector<unique_ptr<A>> v;
auto a = new A(10);
unique_ptr<A> pa(a);
v.push_back(move(pa)); // move(pa);
for (auto& i: v)
{
cout << i->get();
}
}
It compiles well under g++ 4.8, and I could debug it using gdb. Following this page, I could print out STL vectors using vector v
command.
However, with vector with unique_ptr, I got this error message in gdb.
Cannot perform pointer math on incomplete type "unique_ptr<A, std::default_delet
e<A> >", try casting to a known type, or void *.
What's the problem with it? How can I make unique_ptr complete type to get the content with gdb?
ADDED
I noticed that clang++ in Xcode 4.5 supports c++11 features, so the easiest way might be to use Xcode. I have some issue with command line though (lldb on xcode vs lldb on standalone)
I could use Xcode; lldb works fine on Xcode.
这篇关于如何在矢量< unique_ptr>中打印出内容在Mac OS X上使用gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!