Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Moving from C to C++ - Structured to Object Oriented - a lesson for engineers

The C language formed a a logical base from which C++ - an object oriented language developed. One of the major reasons that it is indeed a logical base is that C and its libraries include a number of elements though which you can write code which is essentially object oriented if you write with the correct design patterns - and adding C++ simply provides tools to make the patterns easier, to provide an environment which supports inheritance and polymorphism, and to enforce additional checks to limit you do running only sensible (correctly chosen) functions.

From last week's C and C++ course, [here] is a C program written using the OO Paradigm.

Switching across to C++ ...
 pointers become object references
 structs become object [members]
 mallocs become new
 function calls with a pointer as first parameter become method calls
and those are pretty direct conversions. I have also replaced printf with count.

The comparative code in C++ is then [this].

Many people who have been 'brought up' on engineeing or structured languages find the whole OO thing a bit of a difficult concept at first, and by writing what's actually a rather good and well structured program in C, and then making changes like the ones above, is a neat way to show them how OO goes together, and the first very clear examples of how it really works. Neat - and very rewarding to teach; it's not an approach that's always needed on our C and C++ courses since delegates backgrounds differ, but it's an approach I'll use if it's going to be the best way for the group I students I have.

(written 2015-03-28, updated 2015-03-29)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C231 - C and C based languages - Introduction to C++
  [317] Programming languages - a comparison - (2005-05-20)
  [318] Choosing a theme - (2005-05-20)
  [336] Targetted Advertising - (2005-06-05)
  [928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
  [2004] Variable Scope in C++ - (2009-01-22)
  [2169] When should I use OO techniques? - (2009-05-11)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [3052] Getting your C++ program to run - (2010-11-15)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [4561] Hello World in C++ - a first program, with the process explained - (2015-10-30)
  [4562] Left shift operator on an output stream object - C++ - (2015-10-30)

C230 - C and C based languages - Revision of C
  [4555] Preprocessor directives in C and C++ - what they mean - (2015-10-27)
  [4566] C - why is slow to write and debug) but fast to run? - (2015-11-01)


Back to
Sockets, time handling and keyboard interrupt handling in C
Previous and next
or
Horse's mouth home
Forward to
Neighbourhood Plan - travel and transport thoughts
Some other Articles
Testing in Python 3 - unittest, doctest and __name__ == __main__ too.
Sorting in Python 3 - and how it differs from Python 2 sorting
Four in a Bed - most popular answers
Neighbourhood Plan - travel and transport thoughts
Moving from C to C++ - Structured to Object Oriented - a lesson for engineers
Sockets, time handling and keyboard interrupt handling in C
Catching up on a week all in a single post (?)
Rail Conference, Nottingham
Server program written in Tcl using sockets
Reading from a URL, and reading Json, from your Tcl script
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 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/mouth/4466_Mov ... neers.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb