1 //A class (the commonality and characteristics of a batch of objects) is an abstraction of an object, and an object is a concrete instance of the class2 //Structure types and struct variables can be used to understand the same struct type can define multiple structural body variables3 //C + + also declares a class type first and then uses struct type to define class variables4 //classes are abstract and do not consume memory, but objects are specific, occupy storage space,5 //with the language Foundation to understand another language is a kind of enjoyment, can understand a lot of new things.6#include <iostream>7 using namespacestd;8 class Time9 {Ten Public: One voidset_time (); A voidshow_time (); - Private: - inthour; the intminute; - intsec; - }; - intMain () + { - Time T1; + t1.set_time (); A t1.show_time (); at Time T2; - t2.set_time (); - t2.show_time (); - return 0; - } - voidtime::set_time () in { -Cin>>hour>>minute>>sec; to } + voidtime::show_time () - { thecout<":"<<minute<<":"<<sec<<Endl; *}
Classes and objects