Including C + +

Source: Internet
Author: User

The inclusion of a class (known as has a) is a software reuse technique in program design. That is, when a new class is defined, the other class is "copied" through the compiler. When a class contains a member of a class type that has already been defined, the constructor with parameters initializes the data member, using the initialization syntax form.

Constructor (meta table): Object member 1 (meta table), ..., object member n (meta table);

1#include <iostream>2#include <cmath>3 using namespacestd;4#include <string>5 6 //calculates the distance between two points using a class containing7 classpoint{8  Public:9Point (DoubleXDoubley) {Ten          This->x =x; One          This->y =y; A     } -Point (point&p) { -cout <<"\tcopy_constract"<<Endl; the     } -     DoubleGetX () { -         returnx; -     } +     DoubleGetY () { -         returny; +     } A Private: at     Doublex, y; - }; - classdistance{ -  Public: - Distance (Point dp1,point DP2):p 1 (DP1), p2 (DP2) { -         Doublex = Dp1.getx ()-dp2.getx (); in         Doubley = dp1.gety ()-dp2.gety (); -dist = sqrt (x*x + y*y); to     } +     Doublegetdist () { -         returnDist; the     } * Private: $ Point p1,p2;Panax Notoginseng     DoubleDist; - }; the  + voidMain () { ADistance D (3.1,5.7), point (4.7,6.8)); thecout << d.getdist () <<Endl; +}
1#include <iostream>2#include <cmath>3 using namespacestd;4#include <string>5 6 //calculates the distance between two points using a class containing7 classpoint{8  Public:9Point (DoubleXDoubley) {Ten          This->x =x; One          This->y =y; A     } -Point (point&p) { -cout <<"\tcopy_constract"<<Endl; the     } -     DoubleGetX () { -         returnx; -     } +     DoubleGetY () { -         returny; +     } A Private: at     Doublex, y; - }; - classdistance{ -  Public: - Distance (Point dp1,point DP2):p 1 (DP1), p2 (DP2) { -         Doublex = Dp1.getx ()-dp2.getx (); in         Doubley = dp1.gety ()-dp2.gety (); -dist = sqrt (x*x + y*y); to     } +     Doublegetdist () { -         returnDist; the     } * Private: $ Point p1,p2;Panax Notoginseng     DoubleDist; - }; the  + voidMain () { ADistance D (3.1,5.7), point (4.7,6.8)); thecout << d.getdist () <<Endl; +}

Including C + +

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.