• Home
  • Forum
  • Terms and Privacy
17ebook! free ebooks! free download!
Complete online surveys and earn cash from GlobalTestMarket


Search here...
     

My fucking in c + + book review – Understanding inheritance and composition!

Posted by admin 28 October, 2010

Get your FREE Diabetes Recipes eBook!My fucking in c + + book review   Understanding inheritance and composition!

1, the derived class inherits the default base class member function, that is, without re-define the premise, yf (), and yX:: f () calls the same function

The combination of class members of class objects must be carried out through the function call, a class constructor calls the base class of the order is then combined class, the final will be the class constructor.

2 If you re-define the base class function, then the base class of the same name as the function of all the auto-hide. The so-called “all” because, in the base class may have more than one overloaded function the same name, they are all hidden

Health coverage is a class of functions assigned to cover the base class function
Function with the same name;
Parameters of the same;
Virtual base class function must have keywords;
Different ranges (derived class and base class).
Hide Health class is assigned the same name blocked function of the same base class

1, the function name the same, but the parameters are different, this time regardless of whether the Virtual keyword base class, base class function will be hidden.
2, the same function name, parameters are the same, but the base class of Virtual Keyword (there is the cover), the base class function will be hidden

The so-called “hidden” does not mean you can not call, but said that when the call yf () is called when the definition of Y in the new f (), to call the base class will have an explicit description of f yX:: f (), were type description only.

3 All constructor, destructor, operator = is not automatically inherited, but the compiler will automatically generate a default constructor, copy constructor, operator =, and correctly call the corresponding base class function, they work well

If you want to define parameters for the sub-class constructor, you must also define the default constructor for subclasses. If the custom of the copy constructor, you must also customize the default constructor

In the sub-class copy constructor, if you want to call the base class copy constructor, you must explicitly call the initialization list, or the compiler automatically calls the default constructor

Operator = in the child class, if you want to call the base class’s operator =, you must explicitly call the function body, or the compiler to do nothing.

# Include
using namespace std;

/ / Inheritance!
class A
{
public:
A (int i = 0) {cout <<“A is doing” < A (const A & i) {cout <<“A Copy is doing” < void print (void)
{
cout <<“A cout” < }
};

class B
{
public:
B (int i = 0) {cout <<“B is doing” < B (const B & i) {cout <<“B Copy is doing” < };

class C: public A / / derived class
{
B b; / / composite classes
public:
/ / Initialization syntax: For the base class constructor is called using the class name; for members of the class, call the constructor using the object name
C (int i = 0): b (i), A (i) {cout <<“C is doing” < / / C (int i = 0): A (i), b (i) {cout <<“C is doing” < / / C (int i = 0): b (i) {cout <<“C is doing” < / / C (int i = 0): A (i) {cout <<“C is doing” < / / C (int i = 0) {cout <<“C is doing” < C (const C & i): A (i), b (ib) {cout <<“C Copy is doing” < / / The place to explicitly call the base class copy constructor, or the compiler calls the base class’s default constructor!
/ / Call this place B if you do not specify a copy constructor, the compiler will call B, the default constructor with no arguments, it is obvious!
void print (void)
{
cout <<“C cout” < }
};

int main ()
{
C c (2); / / construct the order of ABC
/ / C.A:: print ();
/ / C.C:: print ();
C d = c;
/ / D.A:: print ();
return 0;
}
This program has several points:

1 First of all, no matter how the constructor of category C write, initialize the list or how to call, how an order, the order of the structure of each class were unchanged at ABC (the base class, the combination of class, subclass)

C (int i = 0): b (i), A (i) {cout <<“C is doing” <

/ / C (int i = 0): A (i), b (i) {cout <<“C is doing” <

/ / C (int i = 0): b (i) {cout <<“C is doing” <

/ / C (int i = 0): A (i) {cout <<“C is doing” <

/ / C (int i = 0) {cout <<“C is doing” <

2, if not explicitly call b the copy constructor, the compiler will call b the default constructor is very good understanding, if not explicitly call A copy constructor, the compiler will call the default constructor for A !

3, if the definition of A or B do not own a copy constructor, C explicitly call them if the copy constructor is invoked the compiler synthesized copy constructor. If C is not defined copy constructor, the compiler of the synthesized copy constructor will call B’s copy constructor, because the compiler synthesized copy constructor is to order copies of internal members. So in this case will be called A copy of the structure, because the synthesized copy constructor is explicitly called it.

Categories : book review Tags :

Comments

No comments yet.


Sorry, the comment form is closed at this time.

Subscribe via Email


Windows Touch Technics and Technology tablet Solution Manual Smart Security/Hacking Science Related Science/Engineering samsung Review Programming Phones phone Nokia Newspapers netbooks Netbook Mobile Medical/Medicine Laptops Laptop IT Certification Iphone Hobbies Health Graphics and Design Google Game For Women For Men features Ericsson Encyclopedias Economics and Finances Economics/Business deals DB Consumer Electronics Computer Related Computer Comics Apple android about
  • Categories

    • book review
    • Ebook Download
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Archives

    • May 2013
    • April 2013
    • March 2013
    • February 2013
    • January 2013
    • December 2012
    • November 2012
    • October 2012
    • September 2012
    • August 2012
    • July 2012
    • June 2012
    • May 2012
    • April 2012
    • March 2012
    • February 2012
    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
  • Recent posts

    • Samsung J700 Chrome- A complete all-rounder mobile phone
    • Latest HTC Mobile Phone – HTC Touch P4350 Smartphone
    • Tips to Work In Windows Operating System
    • Azeem Azam On The Truth Behind The Transfer Window
    • HTC Hero- Gadget with advanced features
    • Sony Ericsson X1 – the mobile phone that does mobile broadband
    • HTC Sensation Deals ? Unearth The Best Cost-Effective Deal
    • Forthcoming Nokia Cell Phones
    • Brighten the Appearance of Your Home, As Well As Your Mood, With Professional Window Cleaning
    • What Should Form the Basis to Compare Mobile Phones?

Copyright © 2013 17ebook! free ebooks! free download! All right reserved

  • Home
  • Forum
  • Terms and Privacy