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?
}
如果你要採用** C++ **的方式,我建議使用C++庫'std :: string'而不是** C **'char'數組來保存你的字符串。 – 2014-09-04 14:23:30
並且還使用'std :: vector'來代替數組。 – crashmstr 2014-09-04 14:29:40