C ++ code implementation ControlTemplate

Source: Internet
Author: User

Currently, the mainstream development language is C ++, but it does not feel as flexible as the C language. I would like to introduce the code implementation ControlTemplate method, the following is an example of C ++ code:

 
 
  1. FrameworkElementFactoryFe=NewFrameworkElementFactory (typeof (Image), "Image ");
  2.  
  3. BitmapImageBi=NewBitmapImage ();
  4. Bi. BeginInit ();
  5. Bi. UriSource=NewUri (@ "E: ChartControlHanYangChartControlImageMainBackground.jpg ");
  6. Bi. EndInit ();
  7.  
  8. Fe. SetValue (Image. SourceProperty, bi );
  9.  
  10. // Display content of the Control. 2. TextBox)
  11. FrameworkElementFactoryFe2=NewFrameworkElementFactory (typeof (TextBox), "TextBox ");
  12. Fe2.SetValue (TextBox. WidthProperty, 100.0 );
  13. Fe2.SetValue (TextBox. HeightProperty, 100.0 );
  14.  
  15. // Encapsulate the display content to be presented
  16. FrameworkElementFactoryF=NewFrameworkElementFactory (typeof (Grid), "Grid ");
  17. F. AppendChild (fe );
  18. F. AppendChild (fe2 );

From the table above, we can see that int and long are the same. So why do C ++ code need to distinguish between the two data types? This is actually a legacy issue. In a 16-bit programming environment, int requires 2 bytes, and long requires 4 bytes. In a 32-bit programming environment, both types of data are stored in four bytes.

C ++ Builder only generates 32-bit programs, so int and long are the same. In C ++ Builder and BorLand C ++ 5.0, Bool is a real data type. Some C ++ compilers have the Bool keyword, so Bool is not a real data type.

Sometimes Bool is only a typedef, so that Bool is equivalent to int. Typedef actually creates an alias to enable the compiler to draw an equal sign between one symbol and another. The syntax of typedef is as follows: typedef int Bool; this tells the compiler that Bool is the alias of int. It indicates that only the double and float data types use floating point numbers with decimal points ).

Other data types only involve integer values. Although the integer data type can also specify a number with a decimal point, the fractional part is discarded and only the integer part is assigned to the integer variable. For example, int x = 3.75; the value of x is 3. Note that this integer is not rounded to the nearest decimal point. By the way, floating point numbers are rarely used in most Windows programs.

The C ++ code can convert different data types when necessary. Example: short result; long num1 = 200; long num2 = 200; result = num1 * num2; here I want to assign the product of two long integers to a short integer. Although this formula is mixed with two data types, C ++ can be used for conversion. What will happen to the calculation result? The result will surprise you. It is 25536, which is the result of the bypass (wrop.

As shown in Table 1.1, the maximum value of a short integer is 32767. What if I add 1 to the maximum value? The result is 32768. This is actually the same as the car's mileage from 99999 to 00000. To illustrate this, enter and run the program contained in listing 1.3.

In order to avoid the complexity of C ++ and simply not to use C ++ Linus), it is tantamount to a waste of food ." In all areas where C and C ++ are available, C ++ is a better language than C. When I say "better", I mean C ++ has a safer type check, better abstract mechanism, and better database than C.

Of course, there are exceptions in everything. If project 1 you are working on is not large. 2) No abstract mechanism is used in encoding, or even ADT abstract data types, such as std: complex, which does not contain Polymorphism or inheritance), and RAII does not, the exception is also unavailable.

3) You don't need to connect to the basic library, such as smart pointers and containers that simplify resource management. Maybe you can use C. If you do, you don't have to argue with me because I can't refute you. The fields we are talking about here are roughly the areas listed by Bjarne in the "C ++ Application List.

  • A summary of C ++ Language Learning
  • Excellent object-oriented design language-C ++
  • What is the design principle of C ++?
  • Introduction to VC ++ applications and description of Modes
  • How to insert new elements for the C ++ Stack

Even opponents of C ++ may have difficulty finding a reason to say "I still don't need C ++ code ". In my opinion, there is only one reason for rational opposition to C ++ in a practical sense: the confusions brought by the complexity of C ++ offset or even exceed the benefits of the abstract mechanism and library of C ++ in his specific project.

It is worth noting that a trap should be avoided here, that is, once people determine that "C ++ code is not good", this reason will "grow your feet", that is, even if we get rid of the complexity of C ++, they may still insist on not using C ++ and find a bunch of reasons for it.

I assume you are not such a person. However, perhaps most likely, he would say, "The problem is that the C ++ we are using today is not so concise.) your assumptions are not true ." Yes, my assumptions are not true. However, although we cannot eliminate complexity, we can avoid complexity and short-term growth. This is also the main point of this article. I will discuss it later.

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.