Template fonksiyonlar ve sınıflar
Kod:
//---------------------------- 040020340.cpp ------------------------------------------------------------------------ // // // Programmer's Name: N/A // Course-Section: N/A // Creation Date: 20-05-2005 // Date of Last Modification: 23-05-2005 // // // //-------------------------------------------------------------------------------------------------------------------- // // Purpose - Using and understanding the templates. // //-------------------------------------------------------------------------------------------------------------------- // // Input - The bits of the elements of the bit array. // // Output - Some results to screen. // //-------------------------------------------------------------------------------------------------------------------- // // Notes on specifications, special algorithms, and assumptions: // // There is a TempArray class that implements the arrays of any type. // And a Binary class that implemets the byte(bits length is arbitrary) arrays // //-------------------------------------------------------------------------------------------------------------------- #include #include #include using namespace std; //------------------------------------------------ smallest ------------------------------------------------ // // Purpose: Finds the smallest element indices of an array // // Parameters: An array, and its length // // Returns: the indice of the smallest element // // Called-by: main // // Calls to: none //----------------------------------------------------------------------------------------------------------- template int smallest(T &array, int length) if(logic == 0) return i; } return -1; } template class TempArray //------------------------------------------------ TempArray::TempArray ------------------------------------------- // // Purpose: Constructor of TempArray class // // Parameters: Length of the array // // Returns: none // // Called-by: main // // Calls to: none //------------------------------------------------------------------------------------------------------------------- TempArray(int l) //------------------------------------------------ TempArray::~TempArray ------------------------------------------- // // Purpose: Destructor of TempArray class // // Parameters: none // // Returns: none // // Called-by: main // // Calls to: none //------------------------------------------------------------------------------------------------------------------- ~TempArray(void) private: int length; Type *array; }; class Binary return result; } //------------------------------------------------ Binary:perator> ------------------------------------------- // // Purpose: Overloading the > operator for Binary class // // Parameters: The right-hand object // // Returns: true or false // // Called-by: main // // Calls to: none //------------------------------------------------------------------------------------------------------------------- bool operator>(Binary& obj) //------------------------------------------------ Binary::Binary -------------------------------------------------- // // Purpose: Constructor of Binary class // // Parameters: Length of the array // // Returns: none // // Called-by: main // // Calls to: none //------------------------------------------------------------------------------------------------------------------- Binary(int l) while (tmp != 0 && tmp != 1); array[i] = tmp; } cout