【发布时间】:2010-11-14 16:54:40
【问题描述】:
我正在寻找正确的方向。 我有 1 个班级活动
class Event{
private:
vector<string> Question;
char Mode;// 1 = Ascending 2 = Descending 3 = None
string EventName;
public:
Event(string Name){
EventName = Name;
SetQuestionSize();
SetQuestion();
Mode = 3;
}
void SetName(string NewName){
EventName = NewName;
}
void SetQuestionSize(){
Question.resize(15);
}
int ReturnQuestionSize(){
return Question.size();
}
void SetQuestion(){
Question[0]="Enter ";
Question[1]="1 ";
Question[2]="to ";
Question[3]="sort ";
Question[4]="in ";
Question[5]="ascending ";
Question[6]="order, ";
Question[7]="2 ";
Question[8]="for ";
Question[9]="Descending, ";
Question[10]="or ";
Question[11]="3 ";
Question[12]="to ";
Question[13]="ignore ";
Question[14]=EventName;
}
string ReturnQuestion(int Index){
return Question[Index];
}
/*vector<string> ReturnQuestion(){
return Question;
}*/
void SetMode(char NewMode){
if (NewMode == '0' || NewMode == '1' || NewMode == '2')
Mode = NewMode;
}
char ReturnMode(){
return Mode;
}
string ReturnName(){
return EventName;
}
};
这将是第二个对象的成员,它将使用 Event 的函数将数据存储在 Event 的成员中。
我遇到的问题是在我的第二个对象中声明一个 Event 对象数组。在研究时,我遇到了使用指向第一个对象的指针数组的方法,而我猜想的一些运算符“->”与虚函数有关。
class WhatTheyWant{
Event *events[2];
public:
WhatTheyWant(){
events[0]= new Event("Miss");
events[1]= new Event("Dodge");
}
};
我对指针一无所知,我知道我最终将不得不学习它们,但它们是最好的方法还是有更好的方法。
【问题讨论】:
-
我不确定网站的格式,但假设事件包括矢量和字符串库,而 WhatTheyWant 包括事件
标签: c++ arrays oop class pointers