我无法在 ncurses 中创建简单的文件选择。以下代码失败,valgring 说“条件跳转或移动取决于 main.cpp:122 中的未初始化值”
// Create items
m_MenuItems = new ITEM * [ m_Files.size() + 1 ];
int i = 0;
for ( vector < CFile >::iterator it = m_Files.begin(); it != m_Files.end(); ++it, ++i ) {
/* m_MenuItems[i] = new_item((*it).pName->c_str(), (*it).pDesc->c_str()); */
m_MenuItems[i] = new_item("file", "size");
cout << "[" << i << "]: " << (*it).pName->c_str() << ", " << (*it).pDesc->c_str() << endl;
} m_MenuItems[++i] = NULL; // Item list has to be null terminated.
// Create menu
m_Menu = new_menu( (ITEM **)m_MenuItems ); // ! line 122
cout << "Success" << endl;
输出正是这样:
[0]: main.cpp, 6888
[1]: a.out, 106798
[2]: .., 4096
[3]: listdir.cpp, 701
[4]: menu.cpp, 1908
[5]: ., 4096
Segmentation fault (core dumped)
什么可能导致未启动的变量?