2014-09-04 33 views
0

我想使一个成员函数“getList”打印一个名称列表。如何使用指针的指针来打印名单?

但是,我没有任何线索使用指针的指针。

任何意见对我都有帮助。

class Happy 
{ 
    private: 
     MyString name; 
     int money; 
     char* list[100]; // I'd like to save a shopping list here. 
     int index; 

    public: 
     Happy(char* np=NULL, int money=10000); 
     Happy(Happy &r); 
     ~Happy(); 
     Happy &operator=(Happy &r); 

     void use(char* ip, int n); 
     Happy &winner(Happy &r); 
     void setName(MyString &name); 
     MyString &getName(); 
     void setMoney(int money); 
     int getMoney(); 
     char** getList(); // I'd like to print the shopping list with a pointer's pointer. 
     int getIndex(); 
}; 
//---------------------------------------- 
char** Happy::getList() 
{ 
// How should I fill this block so that I could print lists? 
} 
+2

如果你要采用** C++ **的方式,我建议使用C++库'std :: string'而不是** C **'char'数组来保存你的字符串。 – 2014-09-04 14:23:30

+0

并且还使用'std :: vector'来代替数组。 – crashmstr 2014-09-04 14:29:40

回答

0

您可以简单地return list;