In C + +, function templates template and function arguments are pointers and are used in combination with return values

Source: Internet
Author: User

1#include <iostream>2 using namespacestd;3 //using a template function to calculate an expression4template<classType>5 type ABC (type A,type b,type c)6 {7     returna+b+C;8 }9 //evaluating an expression with reference parameter pointersTentemplate<classType> OneType ABC (Type *a,type *b,type *c) A { -     return(*a) + (*B) + (*c); -  the } -  - intMain () - { +     intA=1, b=2, c=3; -cout<<"a="<<a<<", b="<<b<<", c="<<c<<Endl; +cout<<"The result of evaluating an expression using a function template is: \ n"; ACOUT&LT;&LT;ABC (a,b,c) <<Endl; at     floatf=4, d=0.6, e=2.3; -cout<<"f="<<f<<", d="<<d<<", e="<<e<<Endl; -cout<<"The result of evaluating an expression using a function template is: \ n"; -COUT&LT;&LT;ABC (f,d,e) <<Endl; -     int*p2,*q2,*R2; -p2=&A; inq2=&b; -r2=&C; to      +cout<<"*p2="<<*p2<<", *q2="<<*q2<<", *r2="<<*r2<<Endl; -cout<<"The result of evaluating an expression with a reference parameter pointer is:"<<Endl; theCOUT&LT;&LT;ABC (P2,Q2,R2) <<Endl; *     return 0; $}

The program has two template functions, type ABC (type A,type b,type c), type ABC (type *a,type *b,type *c) two parameters are different;

The result of the Code debugging operation is:

In C + +, function templates template and function arguments are pointers and are used in combination with return values

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.