Basic Methods of object oriented programming (MFC)

Source: Internet
Author: User

Not to mention directly accessing the code

#pragma onceclass Shape{public:Shape(void){}virtual ~Shape(void){}virtual void Draw(CDC *pDC) = 0;void SetRect(int left, int top, int right, int bottom){m_rc.SetRect(left, top, right, bottom);}void offest(int x, int y){m_rc.OffsetRect(x, y);}protected:CRect m_rc;};class CCircle :public Shape{public:CCircle(void){}~CCircle(void){}virtual void Draw(CDC *pDC){pDC->Ellipse(m_rc);}};class CSquare :public Shape{public:CSquare(void){}~CSquare(void){}virtual void Draw(CDC *pDC){pDC->Rectangle(m_rc);}};class CRoundSquare :public Shape{public:CRoundSquare(void){}~CRoundSquare(void){}virtual void Draw(CDC *pDC){POINT pt = { 10, 10 };pDC->RoundRect(m_rc, pt);}};

Picture

How to draw

Where to draw

In this example

protected:CArray<Shape*, Shape*> m_Shape;

The advantage of using pointers is that you can perform the following operations:

m_Shape.Add(new CCircle());m_Shape.Add(new CSquare());m_Shape.Add(new CRoundSquare());

The above method can be used for reference. We have a lot of objects inherited from different classes of the same class.

Before a class is instantiated, all operations are abstracted to itself (data) possible operations may involve some possible methods, such as drawing a rectangle and moving it. So what this class can do is to use any desired class to implement its own objective class. data is actually details

When getting an object, you can operate on it, that is, develop on the basis of the most primitive class object, call the member function, make this object full, in this case, many local parameters are obtained as real parameters of class functions.

This is like an animal, which has many subjects and genetic characteristics. When it comes to every animal, we will know its characteristics in detail.

The world is complicated. When we use all our resources to achieve our purpose, our purpose is achieved. We think everything is done.

In fact, our class is probably a handler for other classes to achieve their goals.

Mutual reference between classes constitutes a complete program

The interaction of all people in the world constitutes this society.

The top class and instance should exist in the program, such as the app class in MFC.

Followed by the program management system computer and then human

But humans are definitely not the ultimate goal or there is a higher category than humans.

They don't care about us, humans, that is, we humans, but they're just a tiny child in their eyes.

Haha think too much ............

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.