如何在矢量< unique_ptr>中打印出内容在Mac OS X上使用gdb [英] How to print out the content in vector<unique_ptr> with gdb on Mac OS X

查看:561
本文介绍了如何在矢量< unique_ptr>中打印出内容在Mac OS X上使用gdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS X上使用C ++ 11功能。我下载了g ++ 4.8.1与端口。



这是测试代码。

  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.

这篇关于如何在矢量&lt; unique_ptr&gt;中打印出内容在Mac OS X上使用gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆