CPP templates-Examples of ADL applications

Source: Internet
Author: User
Examples of ADL applications:

1. youyuan name insertion:

The membership function declaration in the class can be the first declaration of the membership function. See
The following example:

Template <typename T>
Class C {
...
Friend void F ();
Friend void F (C <t> const &);
};

Void G (c <int> * P)
{
F (); // Error
F (* P); // OK
}

Generally, the object meta declaration is invisible in the peripheral (class) scope.
If the class in which the youyuan function is located belongs to the dataset of the ADL Association class
The peripheral class can be found in the membership statement.

2. Plug-In Class Name

If the name of the class is inserted in the scope of the class, the name is
The name of the plug-in class. It can be seen as an unrestricted name in the scope of this class.
It is also an accessible name.
For example:

# Include <iostream>

Int C;

Class C {
PRIVATE:
Int I [2];
Public:
Static int F ()
{
Return sizeof (C );
}
};

The class template can also have the plug-in class name, which can be followed by the Template
If the real parameters are not followed by the template parameters, they represent parameters.
Class that represents real parameters, for example:

Template <template <typename T> class tt> Class X
{};

Template <typename T> Class C
{
C * A; // correct, equivalent to C <t> *;
C <void> B; // correct
X <C> C; // Error
X <: C> D; // Error
X <: C> E; // OK
}

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.