C + + object model--a single inheritance with overrides

Source: Internet
Author: User

there is a single inheritance of overrides

The base class is overridden in a derived class . print () function.

Derived_overwrite.h#pragma once#include "Base.h" class Derived_overrite:public Base{public:    derived_overrite ( int);    Virtual ~derived_overrite (void);    virtual void print (void) const; Protected:    int iderived;};

  

Derived_overwrite.cpp#include "stdafx.h" #include "derived_overwrite.h" Derived_overrite::D erived_overrite (int i) : Base (0) {iderived = i;cout<< "Derived_overwrite::D erived_overwrite ()" <<ENDL;} Derived_overrite::~derived_overrite (void) {cout<< "Derived_overwrite::~derived_overwrite ()" <<ENDL;} void Derived_overrite::p rint (void) const{cout<< "Derived_overwrite::p rint (), iderived" << iderived < < Endl;}

  Base ,derived_overwrite the class diagram is as follows:

rewrite print () the function behaves as follows in the virtual function table:

in order to verify the above C + + object Model, we write the following test code.

C + + object model--a single inheritance with overrides

Related Article

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.