1#include <iostream>2#include <cstdlib>3#include <cstring>4#include <vector>5 using namespacestd;6 7 8 classAVP9 {Ten Private: One Char*name; A Public: - AVP () - { theName =NULL; - } - -AVP (Const Char*_name) + { -Name =New Char[Strlen (_name) +1]; + strcpy (name, _name); A } at Char*GetName () - { - returnname; - } - }; - in classRead: PublicVector<avp*> - { to Public: + BOOLstartup () - { theavp* A1 =NewAVP ("Apple"); * Push_back (A1); $A1 =NewAVP ("Orange"); Panax Notoginseng Push_back (A1); -A1 =NewAVP ("Pear"); the Push_back (A1); + A } the Staticread*getinstance () + { - if(Instance = =NULL) $Instance =NewRead (); $ returninstance; - } - voidprint () the { -Iterator it =begin ();Wuyi for(; it! = End (); + +it) the { -cout<< (*it)->getname () <<Endl; Wu } - About } $ protected: - Read () - { - } A Private: + Staticread*instance; the - }; $read* read::instance =NULL; the intMain () the { theRead::getinstance ()startup (); theRead::getinstance ()print (); - in the return 0; the}
If you do not understand the read class from the public vecotr<avp*> inheritance, you can,vector<avp*> _AVP;
The Read class inherits from _AVP, so it's a good idea to look directly at the code
Classes inherited from vectors