Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
C and C based languages module C233
OO in C++ - beyond the basics
Exercises, examples and other material relating to training module C233. This topic is presented on public courses Learning to program in C and C++, C++ for C Programmers, C and C++ Programming, Learning to program in C and C++, C and C++ Programming

If you want to define one object that's similar (but not identical) in structure and behaviour to another, you do so through inheritance. If you then have an array of similar objects, you can have C++ decide which particular behavious to use on each element in turn and this is known as polymorphism. In C++, you can define a type of object that inherits its behaviour from seveal others if you wish, and you can group toghether a whole lot of similar types of objects into modules - both of these are more advanced facilities that we cover in this module.
Articles and tips on this subjectupdated
4560Variables, Pointers and References - C and C++
In C, you can address a memory location storing a value directly by its variable name, or you can access it via its address using a variable that contains that address - a pointer - declared using an * in the declaration, and you can then use:   * to mean contents of   & to mean ...
4559When do I use the this keyword in C++?
Question: When do I use the this keyword in C++? Answer: When I expliciy need (or want) to refer to a member variable or object within the current object. Example:    class Transport{       public:          Transport(int);          int ...
4377Designing a base class and subclasses, and their extension, in C++
My first technical post for 2015 - looking back at some of last year's new C++ examples. Oh - OK - I'm writing this on 1st January and these examples were written and uploaded yesterday, so they're nothing like as old as it sounds. On Monday and Tuesday, I wrote classes from scratch and looked at basic ...
4375Final examples for 2014 - and a look at our 2015 training course options
Following on from yesterday's examples [here] in which I talked you through, with links to code samples, the design and creation of a class, starting off with a description of its behaviour in the form of a test program and adding a test object class too, I'm now adding two short sample programs to make ...
4356Object factories in C++, Python, PHP and Perl
Raw materials are converted into a manufactured product in a factory or by a factory procedure, and the sort of product you can make depends on both the raw material that's supplied and on the capability of the factory. And so it is with Object Oriented Computer Programming - supply raw material ...
3979Extended and Associated objects - what is the difference - C++ example
When you use inheritance, you create a tree of object types, where one type is based on another. For example, you define a base class of "transport" and then you extend that to define similar classes with extras called "bus" and "train". That's a very different matter to using a class connected in ...
3811Associated Classes - using objects of one class within another
Wheh you're designing an object oriented class, you'll often use other objects within it. For example, you may design a Ferry object and within it use a Time object (for when it's scheduled to leave, perhaps):   Ferry *mersey = new Ferry(new Time(17,45),14); There's really no special syntax ...
3508Destructor methods in C++ - a primer
Constructor methods - named pieces of code which create a new object - are key to any object oriented program / programming. Without objects, an object oriented program isn't really an object oriented program, and they need to be created somehow. But what happens at the other end of the life cycle? When ...
3251C++ - objects that are based on other objects, saving coding and adding robustness
In a previous article ([here]), I talked about how we introduce the basic concepts of classes, methods and objects on our C++ courses. I'm now going to give you some links to the next series of example which I wrote during that same course. Having covered object basics, we moved on to look at related ...
3244C and C++ - preprocess, compile, load, run - what each step is for
C and C++ original source code goes through a number of steps on its way to becoming a runnable program. 1. The C Preprocessor is run on the original source. This takes the source lines that start with a # character and acts on them as directed. (It does a bit more too - more about that anon!) 2. ...
3142Private and Public - and things between
A public train service is one which is available for anyone to travel on; a private one only takes limited passengers as invites / made available by the operator. And there could be intermediate levels too - I understand that at times the British Transport Police protect the last train from Weymouth ...
3123C++ objects - some short, single file demonstrations
One of the key features of the object oriented paradigm is that it provides a system through which code that's naturally associated with one type of data is accessed through a single closely defined and controlled set of calls (its API / Application Programmer Interface) ... so it's natural on a larger ...
3124C++ - putting the language elements together into a program
On the final day of the C++ course yesterday, I demonstrated a number of advanced features and pulled together various strands that we had been learning through the week. At one level, each feature of the language can be explained and taught, but there's a further level that's need to show how they ...
3056C++ - a complete example with polymorphism, and how to split it into project files
One of the things that newcomers to Object Oriented projects find most difficult is to know how all the various parts of the OO paradigm are related to each other - and that's especially the case on larger C++ projects, where the number of files of source involved is likely to be substantial. Yesterday ...
2577Complete teaching example - C++, inheritance, polymorphism
On yesterday's C++ course, I provided a final example which illustrated polymorphism, and showed how even the simple example was best written, split, ito no less that seven source files. 1. The main C++ source code - for my example, a simple demo test harness See http://www.wellho.net/resources/ex.php4?item=c051/further.cpp 2. ...
2845Objects and Inheritance in C++ - an easy start
We can end up with a lot of files when we do even a simple C++ example to show inheritance - a file for the main program, a file each for the base class and subclass, and a header file for the prototypes for each of the base class and subclass too. So it's much easier to do it all as one file - but ...
801Simple polymorphism example - C++
I've been preparing some new C++ notes, in particular showing how you can create an array of objects of different derived types, and then call methods on each object and have the run time environment select which particular piece of code is to be run each time around a loop (experienced OO programmers ...
925C++ - just beyond the basics. More you can do
Things you can do in C++ ... just a bit beyond the first basics of a class: 1. You can declare that a method is const if it doesn't change any of the instance variables and that will make it a bit more efficient when you run it. 2. You can refer to an instance variable within a method using this-> ...
1819Calling base class constructors
In all object oriented languages, you have a facility called inheritance where you can define one type of thing ("class of object") based on another, and the newly defined class ("subclass" or "extended class") takes the initial ("base") class as it starting point. In your code for your base class, ...
1674What a lot of files! (C++ / Polymorphism demo)
There were no less than SEVEN files in the example I wrote to show a "simple" demonstration of polymorphism in C++ yesterday ... 1. The methods for a base class of file objects - Film.cpp 2. The extra methods on top of the base class for a derived class of Blockbuster objects - Blockbuster.cpp 3. The ...
1572C - structs and unions, C++ classes and polymorphism
C's structs allow you to define a variable type in which you can hold a variety of elements by name ... and that's very similar to how you define all the variables within a C++ class. In a C++ class, though, you also define your methods which take that language forward into the Object Oriented world. C's ...
1217What are factory and singleton classes?
Do you find some of the OO terminolgy baffling? Once you've learnt about constructors and methods, inheritance, overloading and polymorphism and statics, you might think you're there. Then someone mentions a "factory class" or a "singleton" ... Fear not - factory and singleton classes are posh names ...
831Comparison of Object Oriented Philosophy - Python, Java, C++, Perl
There are two different philosophies that have been adopted by the authors of Object Oriented languages. The first approach is to set the thing up in such a way that a programmer who uses someone else's code as the basis for his isn't going to be trusted to use that other person's code in a sensible ...
798References and Pointers in C++
I always know that when I'm running a C Course, the concept of pointers will be one of the more difficult elements for some of the delegates to grasp. No big deal, I can explain them in a number of ways, provide examples from different angle, and we'll be over the hiccough in progress in not too long ...
Examples from our training material
Accounts.cpp   C++ factory returning different object types
Make_3   Makefile for our C++ inheritance / polymorphism demo (2)
NewHotel001.cpp   Second program to use our HotelRoomBooking - Array
NewHotel002.cpp   Second program to use our HotelRoomBooking - Vector
accom2.cpp   Class storing strings within an object
accom3.cpp   An array of objects
accom4.cpp   An array of objects
accomchooser.cpp   Class using classes and derived classes with inheritance
allinone.cpp.ex   Inheritance and Polymorphism example (all in 1 file)
animal.cpp   the code for the base class (2)
animal.h   Header file for a base class (2)
beasts.cpp   Definition of polymorphic class methods
beasts.h   Definition of polymorphic class headers
booklet.cpp   Destructors - how and when they run
classinclass.cpp   Associated objects - one object used within another
first_inheritance.cpp   What is Inheritance / how is it implemented in C++ (1)
hotel.cpp   Class member code
hotel.inc   Class descriptor
human.cpp   second subclass of animal - human (2)
human.h   extended subclass definintion
loader   Complete first Polymorphism example
makefile   Compile / Load instructions for examples in this module
melkshamhotel.cpp   Derived class member code
melkshamhotel.inc   include file to define melkshamhotel
midi.cpp   Inheriting a Constructor
pert.cpp   Overloading, Inheritance, Virtual, Polymorphism and more
pet.cpp   code for second subclass - pet (2)
pet.h   Definition of subclass headers (2)
petite.cpp   Abstract base class, two subclasses, polymorphic array
ptx.cpp   inheritance and polymorphism - bus and train
regionhotel.cpp   Derived class member code
regionhotel.inc   include file to define region hotel
second_inheritance.cpp   What is Inheritance / how is it implemented in C++ (2)
shapes_01.cpp   Complete inheritance and polymorphism demo
shapes_02.cpp   Complete demonstration - data stored on the heap
shapes_03.cpp   Overloading +
shapes_combined   All the files for the shape demo on one page!
small.cpp   Declare, define, use a class - all in one file
testh.cpp   First denmo of polymorphism
testh2.cpp   Demo of polymorphism across an array
tinin.cpp   base class, extended class, test code
trans.cpp   Associative classes example
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
Deriving one class from another - Inheritance.
Inheritance and access control.
Packaging classes into modules.
Extending Classes.
Multiple inheritance.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/C233.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb