#include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ //class class phone { public: string name; int price; string color; phone(string n1, int p1, string c1) { name = n1; price = p1; color = c1; } void show() { cout<<"\nproduct = "<show(); //3.物件陣列變數(第一種) phone a3[3] = { phone("iphone X",35000,"white"), phone("oppo 10", 15000, "blue"), phone("samsung G 12",25000,"red") }; //注意:陣列設定值{};,要加上; a3[0].show(); //4.物件陣列變數(第二種):失敗(php可以) // phone a4[3]; // a4[0] = phone("iphone X",35000,"white"); // a4[1] = phone("oppo 10", 15000, "blue"); // a4[2] = phone("samsung G 12",25000,"red"); //5.物件陣列指標變數 phone * a5[] = { new phone("iphone X",35000,"white"), new phone("oppo 10", 15000, "blue"), new phone("samsung G 12",25000,"red") }; //注意:陣列設定值{};,要加上; a5[0]->show(); return 0; }