C ++ Primer study note _ 106 _ special tools and technology, primer_106

Source: Internet
Author: User

C ++ Primer study note _ 106 _ special tools and technology, primer_106
Special tools and technologies-Local

 

Classes can be defined within the function body. Such classes are called local classes. A local class defines a type, which is only visible in the local scope that defines it. Different from Nested classes, local class members are strictly restricted.

All the members (including functions) of a local class must be fully defined within the class definition body. Therefore, local classes are far less useful than Nested classes.

In fact, the requirements fully defined by members in the class limit the complexity of local class member functions. Functions in a local class rarely exceed several lines of code. If the number of lines is exceeded, it is hard for readers to understand the code.

Similarly, local classes are not allowed to declare static data members and there is no way to define them.

 

1. Local classes cannot use variables in the function Scope

The names of peripheral scopes that can be accessed by local classes are limited. A local class can only access type names, static variables, and enumeration members defined in the peripheral scope, and cannot use variables in functions defining this class:

Int a, val; void foo (int val) {static int si; enum Loc {a = 1024, B}; class Bar {public: Loc locVal; int barVal; void fooBar (Loc l = a) // OK {barVal = val; // Error, val in the expected function parameter, no! BarVal =: val; // OK, the global variable val barVal = si; // OK, the static variable locVal = B; // OK, using enumerator }};}

 

2. General protection rules apply to local classes

Peripheral functions do not have special access to private members of local departments. However, local classes can set peripheral functions as friends.

[Practice]

In fact, private Members in a local class are almost unnecessary. Generally, all members of a local class are public members. A local class is encapsulated in its local scope. Further information hiding is unnecessary.

 

3. nested local classes

A class can be nested inside a local class. In this case, the nested class definition can appear outside the local class definition body, but the nested class must be defined in the same scope that defines the local class. As usual, the name of the nested class must be limited by the name of the peripheral class, and the declaration of the nested class must appear in the definition of the local class:

void foo(int val){    class Bar    {    public:        //...        class Nested;    };    class Bar::Nested    {        //...    };} 

The class nested in the local class itself is a local class with all the additional restrictions. All the members of the nested class must be defined inside the definition body of the nested class.



C programming language and C Primer Plus which is better?

The former is only an entry-level book. If you want to use C entry-level programming, you can read this book and learn C ++ or JAVA in the future. C primer plus is the most comprehensive .. If you want to develop in C, you can see that he is also a tool book. If you want to study C in depth, you need to read more books at the bottom of C, such as C compiler implementation. C language Assembly knowledge

After learning c primer plus, what should I learn?

I have read a lot of books from the author. The advantage is that the knowledge is wide and the disadvantage is that it is easy to be refined. I personally strongly suggest:
Clear goals-clear programming language-select a good book for good reading, good programming (manual programming is the focus)-select a lot of books (the same programming language) as a tool book-start to achieve the goal

In addition, if you only want to practice applications (such as Enterprise Portal and office platform websites), Learning data structures is of little use. The application algorithm has already been saved to the relevant class library. If you are not interested in it (Love coding algorithm, curious ...), The help is really not too great.
Assembly language .. First, it is not practical for window design .. It is hard to understand and use. If you do not want to do embedded-related things, you really don't need it. If you are really interested, the current compilers all come with disassembly, you can have a look at it.

As an enterprise portal and an Office Platform website, php, mysql, and HTML must be used. You can use dreamweaver, wamp, and other environments, I used "elaborate on php" when I first studied it. As for HTML, there are entry-level documents everywhere on the Internet, which are basically used for the interface of the artist. dreamweaver is very simple.

Besides php, java is also a good choice. Although I don't know it, java is still very powerful in website maintenance and so on. I don't know it, but I can only make one proposal.

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.