Left-write of real parameters in the viual C ++ Condition Statement

Source: Internet
Author: User

All those who have learned programming know that there are only three control structures in programming, namely, order, loop, and condition. Any program design can not be separated from these three structures. This time I will only introduce a small technique about conditional statements-real parameter left writing. The following uses the if statement in Visual C ++ 6.0 as an example.

Now we use MFC to compile a simple drawing program. When you press the left mouse button, drag the mouse to draw the mouse path in the workspace. When the left mouse button is released, the drawing is stopped. The code for each module I designed is as follows:

First, add three member functions onlbuttonup, onlbuttondown, and onmousemove to the View class, add the Private Members m_mypoint and m_oldpoint of the two cpoint classes, and then add a bool variable m_downorup.

The code of the onlbuttonup function module is as follows:

M_downorup = false;

The view constructor code is as follows:

M_mypoint = 0;

M_oldPoint-0;

M_downorup = false;

The code of the onlbuttondown function module is as follows:

M_downorup = true;

M_mypoint = point;

M_oldpoint = point;

The code of the onmousemove function module is as follows:

Cclientdc DC (this );

Cpen mypen (ps_dashdotdot, 1, RGB (0, 0, 255 ));

Cpen * oldpen = Dc. SelectObject (& mypen );

If (m_downorup = true)

{

DC. moveTo (m_mypoint );

DC. lineto (point );

M_mypoint = point;

}

After finishing the above work, I was very happy to run it. After running it, I drew the mouse track line without pressing the client area. After thinking about it, I went to see if any code was wrong, however, I did not find any errors. Finally, I carefully reviewed each line of code. After a great deal of effort, I found that the if condition was wrong, I wrote "=" as "=". Let's think about it. If we write "true" before it, and if the equal sign is written as the value assignment symbol, the compiler will report an error, we will also detect problems early and save a lot of time and material resources for the software development process.

The reason for writing this is that these two symbols have completely different meanings. An equal sign is the meaning of a value assignment, and the value on the right is assigned to the right. Here, real parameters cannot be placed on the left; the two equal signs indicate comparison to see if they are equal. Real parameters can be placed on the left.

Okay, this is all here. Thank you!

 

 

 

 

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.