开发者

Declaring GPtrArray object local

开发者 https://www.devze.com 2023-02-20 18:14 出处:网络
I have creat开发者_StackOverflow中文版ed a pointer using g_ptr_array_sized_new() of GPtrArray class in a local method.

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

精彩评论

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