开发者

Declaring GPtrArray object local

I have creat开发者_StackOverflow中文版ed a pointer using g_ptr_array_sized_new() of GPtrArray class in a local method.

But when I come out of the for-loop, that pointer is NULL. What is wrong? Here is the implementation within local method:

GPtrArray* myMethod()
{
    GPtrArray *typePtr = g_ptr_array_sized_new(10);

    string *str1;
    for(int i = 0; i < 5; i++)
    {
        str1 = new string();
        str1->assign("Name"); 
        g_ptr_array_add(typePtr,(gpointer)str1->c_str());
    }
    return typePtr;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜