# Include <iostream> # include <conio. h> using namespace STD; const int size = 8; Template <class T> class smemory {// defines the class template smemory t data [size]; // The type is t, the data [] array with a length of size is the data member int count; public: smemory () {COUNT = 0;} void mput (t x); // mput () the type of function parameter X is t mget (); // It is declared that the type of return value is T. The member function mget ()}; Template <class T> void smemory <t> :: mput (t x) // defines the member function mput (). The parameter type of the function is t, this function is used to assign values to each element in the data array of data members {If (COUNT = 8) {cout <"memory is full"; return;} data [count] = X; count ++;} template <class T> T smemory <t>: mget () // defines the member function mget (). The return type of the function is T, this function is used to retrieve each element of the data array of the data member {If (COUNT = 0) {cout <"memory is empty"; return 0 ;}count --; return data [count];} int main () {smemory <int> mo1; int I; char CH = 'a'; // instantiate smemory, and create the object mo1 smemory <char> mo2; // instantiate the smemory and create the object mo2 for (I = 0; I <8; I ++) {mo1.mput (I ); // call the member function mput () mo2.mput (CH); ch ++; // call the member function mput ()} cout <"Get mo1 => "; for (I = 0; I <8; I ++) cout <mo1.mget (); // call the member function mget () cout <"\ ngET mo2 => "; for (I = 0; I <8; I ++) cout <mo2.mget (); // call the member function mget () getch ();}