"C + + Primer the 16th chapter" 2. Template argument Inference

Source: Internet
Author: User

template argument inference : for function templates, the compiler uses function arguments in calls to determine template parameters, and the process of determining template parameters from function arguments is called template argument inference.

Type conversions and template type parameters

As always, the top-level const is ignored either in the formal parameter or in the argument.

Const Conversion: You can pass a reference (or pointer) of a non-const object to a const reference (or pointer) parameter.

• Array or function pointer conversions: An array argument can be converted to a pointer to its first element. Similarly, a function argument can be scratched to convert a pointer to the function type.

1Template <typename t> t fobj (t, T)//The actual argument is copied2Template <typename t> T fret (ConstT&,Constt&)//References3 4 stringS1 ("a value");5 ConstSTRNG S2 ("another value");6Fobj (s1, S2);//call Fobj (String, string); Const is ignored7Fret (s1, S2);//Call fret (const string&, const string&); const is ignored8 9 inta[Ten], b[ the];TenFobj (A, b);//Call Fobj (int*, int*); OneFret (A, b);//Error

"C + + Primer the 16th chapter" 2. Template argument Inference

Related Article

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.