Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses

I've added three new C++ examples to our library following on from last week's C++ course. Each of them is one step beyond "hello world" with regard to the particular feature it's showing, but isn't so advanced and showing so many options that it confuses the newcomer - at least that's the theory. See what you think in practise ;-)

An example in which I've redefined the operators "+" and "*" for a class, so that we can combine "mean time between failure / service" objects. And the example also overrides how the << method on an output file stream works for objects of this type so that we can output them in a default format. See [source].

How to define, throw and catch exceptions in C++. Exceptions are an excellent failsafe way of trapping problems - as opposed to checking for errors which isn't intrinsically failsafe because you need to know what all the possible errors are ahead of time. See [source].

References and Pointers can both be used to (in effect) pass data into a function / method so that it's read/write - i.e. in such a way that the original data in the calling method will be changed to reflect changes made via the passed in variable. This example shows a (default) call-by-value function which doesn't work as you would wish - it swaps over copies of variables leaving the original untouched. But it then showx how to do it with references and with pointers, and also how you can do it with a template so that my "swapper" routine used is generic across all appropriate data types. [source].
(written 2011-11-06)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C234 - C and C based languages - Further C++ Object Oriented features
  [3982] Using a vector within an object - C++ - (2013-01-19)
  [3430] Sigils - the characters on the start of variable names in Perl, Ruby and Fortran - (2011-09-10)
  [3238] Bradshaw, Ben and Bill. And some C and C++ pointers and references too. - (2011-04-09)
  [3124] C++ - putting the language elements together into a program - (2011-01-08)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3057] Lots of things to do with and within a C++ class - (2010-11-16)
  [2849] What are C++ references? Why use them? - (2010-07-02)
  [2717] The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
  [2673] Multiple Inheritance in C++ - a complete example - (2010-03-12)
  [2576] What does const mean? C and C++ - (2010-01-15)
  [2005] Variables and pointers and references - C and C++ - (2009-01-23)
  [2004] Variable Scope in C++ - (2009-01-22)
  [1819] Calling base class constructors - (2008-10-03)
  [1159] It can take more that one plus one to get two. - (2007-04-22)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [802] undefined reference to typeinfo - C++ error message - (2006-07-15)
  [801] Simple polymorphism example - C++ - (2006-07-14)

C236 - C and C based languages - Exceptions
  [3068] Throwing your own exception in C++, and catching it - (2010-11-24)
  [2622] Handling unusual and error conditions - exceptions - (2010-02-03)
  [1875] What are exceptions - Python based answer - (2008-11-08)
  [799] The case for exceptions - (2006-07-11)

C238 - C and C based languages - Templates
  [3810] Reading files, and using factories to create vectors of objects from the data in C++ - (2012-07-21)
  [3388] Templates in C++ - defining a family pattern of methods / functions - (2011-08-12)
  [3252] C++ - unknown array size, unknown object type. Help! - (2011-04-17)
  [3245] Collections in C and C++ - arrays, vectors and heap memory blocks - (2011-04-12)
  [1478] Some new C programming examples - files, structs, unions etc - (2007-12-19)


Back to
Destructor methods in C++ - a primer
Previous and next
or
Horse's mouth home
Forward to
The skull above the door in Melksham Town Hall
Some other Articles
Olympic Torch - dates and places in Wiltshire in 2012
A colleague and friend who changed my life
Melksham has a heart - have your picture taken and support the defibrillator appeal
The skull above the door in Melksham Town Hall
Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses
Destructor methods in C++ - a primer
Melksham Forward - meeting summary and pictures
Cold call contacts - preference services and turning off spam sales approaches
Well House Manor - Winter Warmers - Open 7 days a week, 11 to 5 ++
Coaches from Trowbridge and Melksham to London
4254 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 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3509_Ope ... urses.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat