Deep Exploration C + + object model The last note of reading notes

Source: Internet
Author: User

The 6th chapter is mainly about the semantics of the implementation period, the main content is about the array in the construction and deconstruction is how to carry out.

The 7th chapter mainly tells about the related content of template.

These two chapters are scattered in the "effective C + +", "more effective C + +", "C++primer" "c++templates Chinese Version" and other books, if interested please read the corresponding books.

This reading note mainly wants to talk about the understanding of semantics.

I think that C + + programming can be easily divided into three levels: grammar layer, Language semantic layer (like "Deep Exploration of the C + + object model," The semantics), the program semantics layer.

The grammar layer is easy to understand and easy to learn. There are a lot of books on C + + grammar, and you can learn it by looking for basic and more studies. But reaching that level only reaches a very low-level level. For example, I want to save five integers, then I write int n1,n2,n3, n4,n5; Yes, but if so, it is likely to be troublesome in later processing, although the above statements fully conform to the C + + syntax requirements.

In fact, if you want to have a good grasp of C + + grammar is not easy, you need to read books and continuous practice. Even a good grasp of C + + most of the syntax is just the first step to finish long March.

One level higher than the grammatical layer is the language semantic layer. Language semantic layer is my own creation of the ranking, then what is the language semantic layer? A good explanation is that the written statement conforms to semantics according to the specific implementation of the language after the grammar is followed. If the "C + + Primer" is a good book on C + + grammar, then "deep Exploration of C + + object Model" is a good explanation of C + + language semantics books. Language semantics can be simply understood as the true semantics of the statements we write.

For example, I can write down

class Test
{
public:
    Test(wstring) : m_strName()//A
    {
          m_strName = _T(“”);   //B
    }

private:
    Wstring m_strName;
}

There are two ways to initialize m_strname at this point, method A or B. Although both A and B meet the requirements of grammar, which is more semantic? Of course a statement (for specific reasons see the depth of the C + + object model), so according to semantics we should use a statement.

The language semantic layer described in this article refers to the content, which is the semantics of C + + language. It takes more effort and practice to reach this level than to reach all levels. Although this level is not more difficult than the last level, but to really reach this level is also very easy, as long as efforts can be achieved.

You can understand program semantics in this way: After meeting the requirements of grammar and language semantics, we have now implemented a function, but we have to use the method is modifiable, comprehensible, time efficiency, space efficiency and so on. If language semantics is understood from the perspective of sentence or a single class, procedural semantics is to understand from the height of the whole program whether the program we write is graceful and graceful, and whether it makes people feel fulfilled and satisfied. That means we have a good solution to the problem.

If you want to reach this level, we need unremitting efforts and good understanding. For example, you need to sort a large array. The bubbling method is generally not as good as a quick sort; For example, if you need to have an array that can hold a type, and the type is indeterminate, then use the Save void* Pointers and coercion type conversions are certainly not as good as using vectors similar to those in STL. The above two examples are simple for the differences in the semantics of different programs.

Mountains in the distance, the road at the foot, I wish we can reach the summit of the Dream.

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.