【发布时间】:2019-10-17 18:23:58
【问题描述】:
如果你从同一个类中调用 main 中的三个对象,如下所示:
customer one(856756, "New York");
customer two(896557, "New York");
customer three(896571, "Washington");
当您有这样的课程时,您如何能够打印出具有相同城市共同点的人的列表:
class customer {
public:
customer(int RegNr, string City) { this->RegNr = RegNr; this->City = City; }
customer(){}
~customer() { cout << "Customer with registration number " << RegNr << " has been destroyed." << endl; }
void setRegNr(int RegNr){this->RegNr=RegNr;}
void setCity(int City) { this->City; }
string getCity() const { return City; }
int getRegNr() const { return RegNr; }
private:
int RegNr;
string City;
};
【问题讨论】:
-
比较每个实例的
getCity()输出 -
@ignacio 如果我比较客户一和二,它只会检查这两个。如何“动态”比较它们,以便比较创建的每个新对象?
-
要动态比较它们,您必须创建一个数组。