Example of a function template (ii) full-specificity example

Source: Internet
Author: User

The definition of a function function2.h:

#ifndef Function2_h#defineFunction2_h#include<string>#include<cstring>#include<iostream>Template<typename t>T Mymax (ConstT P1,ConstT p2) {Std::cout<<"default Func"<<Std::endl; returnP1 < P2?P2:p1;} Template<>Const Char* Mymax (Const Char* STR1,Const Char*str2) {Std::cout<<"char* func"<<Std::endl; return(STD::STRCMP (STR1, str2) <0) ?str2:str1;}#endif //Function2_h

Test file Main.cpp:

#include <iostream>#include"function2.h"using namespacestd;intMain () {cout<< Mymax ( -, -) <<Endl; cout<< Mymax ("Hello"," World") <<Endl; return 0;}

Results:

Example of a function template (ii) full-specificity example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.