C + + Programming Method 4: member function templates

Source: Internet
Author: User

Template for member functions:

A member function of a normal class can also be defined as a function template, such as:

Class Normal_class

{

Public

int value;

Template<typename t> void Set (T const &V)

{

value = Int (v);//Defined within class

}

Template<typename t> T get ();

};

Template<typename t> T Normal_class::get () {return T (value);} Defined outside the class

The member functions of the class template can also have additional template parameters, such as:

Template <typename t0>class  A {public:    T0 value;    Templatevoidsetconst&V)    {        = T0 (v);  within the class's internal definition     }    templateget();}; Template<typename t0> template<typename t1>T1 A::getreturn T1 ( Value); }// The external definition of the class

C + + Programming Method 4: member function templates

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.