TSINGHUAX+00740043_2X C + + programming Advanced c7-3

Source: Internet
Author: User
C7-3.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream>using namespace std;struct base1{int x; BASE1 (int x);}; struct Base2{int x; BASE2 (int x);}; struct Derived:p ublic Base1, public base2{int x;derived (base1& A, base2& b);};/ /Please implement BASE1,BASE2, derived constructor base1::base1 (int x) {this->x = x;} BASE2::BASE2 (int x) {this->x = x;} Derived::D erived (base1& A, base2& b): Base1 (a.x), Base2 (b.x) {//derived class construction time to initialize the base class constructor, otherwise there will be a problem. This->x = a.x + b.x;} int main () {int x, y;cin >> x >> y; Base1 a (x); Base2 b (y);D erived D (A, b); cout << d.base1::x << "+" << d.base2::x << "=" << d.x << en Dl;return 0;}

  

TSINGHUAX+00740043_2X C + + programming Advanced c7-3

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.