please dont rip this site

language ccpp cppref EXAMPLES inherit

/ ************************************************************************
 *
 * Purpose:
 * Author:  M J Leslie
 * Date:    26-Oct-98
 *
 ************************************************************************/


#include <stdlib.h>
#include <iostream.h>               // Instead of stdio.h


// ... The base class 'Fabric'
// ... is no different to normal.


class Fabric
{
public:

    Fabric() {};
    ~Fabric(){};

    SetSize(int x, int y)
    {
        Length = x;
        Width  = y;
    }

    SetColour(char *C)
    {
        strcpy(Colour, C);
    }

private:
    int  Length;
    int  Width;
    char Colour[20];
};



// ... The derived class 'Tent'
// ... names 'Fabric' as a base class.


class Tent : public Fabric
{
public:

    Tent() {};
    ~Tent() {};

    SetNumOfPoles(int P)
    {
        Poles = P;
    }

private:
    int  Poles;
};


// ... The derived class 'Clothes' also
// ... names 'Fabric' as a base class.


class Clothes : public Fabric
{
    public:

    Clothes() {};
    ~Clothes() {};
    
    void SetNumOfButtons(int B)
    {
    Buttons = B;
    };
    
    int GetNumOfButtons(void)
    {
    return (Buttons);
    };
    
    private:
    int  Buttons;
};


// ...    Function definitions.

void Init(Fabric &Material);

main()
{  
    Tent       Frame;
    Clothes    Jacket;

    // ... Initialise using the derived methods.
    
    Init(Frame);
    Init(Jacket);

    // .. Initialise using the unique methods.
    
    Frame.SetNumOfPoles(5);
    Jacket.SetNumOfButtons(2);

}

void Init(Fabric &Material)
{
    Material.SetColour("Red");
    Material.SetSize  (10, 20);
}


file: /Techref/language/ccpp/cppref/EXAMPLES/inherit.cc, 1KB, , updated: 1998/10/27 13:57, local time: 2012/5/25 04:44,
TOP NEW HELP FIND: 
38.107.179.230:LOG IN

 ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/techref/language/ccpp/cppref/EXAMPLES/inherit.cc"> language ccpp cppref EXAMPLES inherit</A>

Did you find what you needed?

 
Check out Peter Cousens EXCELLENT
Calculator
7-seg LED chars, port values, resistor color codes and common values, ohms law, wavelength / frequency, RMS and Peak, max value for x bits, etc...
 

Peter Todd has released source and sample projects for his artwork, including his 3d wireframe cube renderer for the PIC 18f6520 This includes examples of hardware developed with free software tools such as gEDA/gschem/PCB, SDCC, gputils and picp all on Linux. http://petertodd.ca/art/source-code/

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .