Use of generic templates in C + +

Source: Internet
Author: User

1#include <iostream>2 using namespacestd;3 //a generic template evaluates the value of an expression4template<classTaclassTb,classTc>5Ta ABC (ConstTa *a,ConstTb *b,ConstTc *c)6 {7     return(*a) + (*B) + (*c);8 }9 intMain ()Ten { One     intA=Ten,*p; A     floatb=2.6,*Q; -     CharC='A',*R; -p=&A; theq=&b; -r=&C; -cout<<"*p="<<*p<<", *q="<<*q<<", *r="<<int(*r) <<Endl; -COUT&LT;&LT;ABC (p,q,r) <<Endl; +     return 0; -}
In the program through Template<class ta,class tb,class tc> make a,b,c3 parameters can be different types, and return the result type is the type of the first parameter;
The results of the debug run are:












Use of generic templates in C + +

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.