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;
}
精彩评论