C + + abstract class One (multiple inheritance and assignment compatibility principles)

Source: Internet
Author: User

//multiple inheritance and assignment compatibility principles#include <iostream>using namespacestd;classpoint{ Public: Point () {a=1; b=2; }    intA; intb;};classPointa { Public: Pointa () {c=3; }    intc;};classPOINTB: PublicPoint, Publicpointa{};voidPROTECTB () {POINTB PB; Point*P1 = &PB; Pointa*PA = &PB; cout<<"PB's Address"<< &AMP;PB <<Endl; cout<<"*p1 's address"<< P1 <<Endl; cout<<"*pa's address"<< PA <<Endl; cout<<"----------------"<<Endl; /*as the observation results: &pb; This operation, C + + compiler is to do the & operator overloaded, C + + compiler for &pb; This operation will take an offset from the type of class that accepts the address point *p1 = &pb; C The + + compiler detects the spatial offset of the memory occupied by the type of point in POINTB memory, and returns the corresponding address because the C + + compiler overloads the & operator, it implements the intrinsic analysis of the assignment compatibility principle operator overloading: operator overloading is essentially is a member function in a global function class that defines a function name is a operator operator. The operator overload is only passed one parameter less than the global function. Conjecture: the C + + compiler compiles all operator-modified operators into a single table when C + + compiles When a operator-modified operator is detected, it gets the operands of the operator and matches the type of the operand with the global function with the operator keyword, and if a match is found, the C + + compiler will directly execute the global function to return the global function. Value as the return value of the operator*/}voidMain () {PROTECTB (); System ("Pause");}

C + + abstract class One (multiple inheritance and assignment compatibility principles)

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.