//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"<< &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)