打印共同具有特定变量值的类对象

问题描述 投票:-1回答:3

如果您从同一类的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;
};
c++ class object
3个回答
© www.soinside.com 2019 - 2024. All rights reserved.