How to analyze the difficult problems in learning C++
This article shows you how to analyze the difficult problems when learning C++. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Many programmers learn C++ to sum up experience, some feel that C++ language is an independent language, not on the basis of C language, you can learn C++ directly without starting from C, just like C++ and Java, the local structure is still different.
C++, as a general programming language, has successfully achieved her original design goals: high efficiency, versatility, extensibility and flexibility; it is a language rather than a system; she gives programmers respect rather than bondage, and so on.
In fact, when learning C++, it also supports a generic programming paradigm called template metaprogramming, whose core is to skillfully use C++ 's template mechanism and object-oriented mechanism to advance the program's processing of data to the compilation time, not at run time. This kind of programming is like functional programming. There are no variables and loops in this design paradigm, but its Turing is complete, so it is called metaprogramming.
Next I'll give a simple example to see the impact of this programming on runtime efficiency. There is such a series of numbers: 1, 1, 2, 3, 5, 8, 13, 21, and so on. The first one and two terms are 1, and each term after that is the sum of the first two items. Now let's program to calculate the value of item N. The procedure is as follows:
/ / CODE # include "stdafx.h" / / compile-time calculation method template / / main template calculates item N of the series struct f {enum {value=f::value+f::value}; template struct f / / specialized template series * * is 1 {enum {value=1};}; the second item of template struct f / / specialized template series is 1 {enum {value=1};} / / long F (long n) {if (name1 | | nimble 2) / / sequence * *. The two items are: 1 directly returns {return 1;} else / / recursive {return F (NMAT 1) + F (NMAT 2);}} int _ tmain (int argc, _ TCHAR* argv []) {std::cout