C ++ Standard Library Study Notes 1-Chapter 2 & chapter 3

Source: Internet
Author: User

--------- Chapter 2 ---------

1. (P11)

C ++ requires that, apart from being modified by typename, any symbol in the template is regarded as a value rather than a type.

Eg.

 

Template <class T>
Class myclass {
Typename T: subtype * PTR;
};

 

 

Here, typename indicates that subtype is a type defined in class T, so PTR is a pointer to T: subtype, otherwise subtype will be treated as a static member, so:

T: subtype * PTR is considered the product of subtype and PTR.

 

2. (P12)

Member template of template class:

In the following example, even if the two types can be automatically converted, such as int and double, an error occurs if we use different template types for assign.

 

Template <class T>
Class myclass {
PRIVATE:
T value;
Public:
Void assign (cosnt myclass <t> & X)
{
// X must have same type as * This
Value = x. value;
}
...
};

 

 

Let's look at this again:

 

Template <class T>
Class MyClass {
Private:
T value;
Public:
Template <class X> // member template
Void assign (cosnt MyClass <X> & x)
{
// Allows different template types
Value = x. getValue ();
}
T getValue () const {
Return value;
}
...
};

 

 

Now, the assign () parameters X and * This are of different types,So the two classes are different.,
You cannot directly access the private and protected members of myclass. Instead,
Getvalue () is used in this example ()

 

3. (P14)

Initialize the display of the basic type

If you use the constructor call syntax without parameters, the basic type is initially setZero

Eg.

 

Int i1; // undefined value
Int i2 = int (); // initialized with zero

 

 

 

4. (P16)

Exception.

① Exception handling is not an error handling

②. Void f () throw (xxx) is f () throw XXX type exception,

Void f () throw () refers to f ()NoIf any exception is thrown, many people may make mistakes.

 

5. (P16)

Namespace.

Eg.

 

Namespace tankywoo {
Class;
Class B;
...
}
...

 

 

Then, using tankywoo: A will make A the meaning of tankywoo: A in the current scope

However, using namespace tankywoo exposes all the names (A and B) in the namespace ).

 

--------- Chapter 3 ---------

 6. (P23)

Namespace
As mentioned in the previous article.
When using any identifier of the C ++ standard library, there are three options: (the following uses cout as an example)
① Directly specify the identifier:

Std: cout <"Tanky Woo" <std: endl;

 

② Using declaration makes it unnecessary to add "std ::"

Using std: cout;
Cout <"Tanky Woo" <std: endl;

 

③ When using directive is used, all identifiers defined in std are valid.

Using namespace std;
Cout <"Tanky Woo" <endl;

 

 

7. Error Handling and Exception Handling
Exception Handling involves a small amount of contact, and the third chapter is also briefly described here, so we will put it here first, and then fill it with experience.

 

8. Configurator)
Same as above.

 

 

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.