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. The C++ source code of the first class that my example used
See
http://www.wellho.net/resources/ex.php4?item=c051/starredhotel.cpp
3. The C++ source code of the second class that my example used
See
http://www.wellho.net/resources/ex.php4?item=c051/selfhotel.cpp
4. The C++ source code of the base class from which my two sample classes were derived.
See
http://www.wellho.net/resources/ex.php4?item=c051/g_hotel.cpp
Because I need to include function / method prototypes into various files so that the comiler can check that calls are valid in isolation from the separate compiles, I have also provided separate header files. In theory it is possible to include these within the four source files above directly, but that is a TERRIBLE practice and you should load them through #includes ...
5. The header file defining the methods in the first used class
See
http://www.wellho.net/resources/ex.php4?item=c051/starredhotel.h
6. The header file defining the methods in the second used class
See
http://www.wellho.net/resources/ex.php4?item=c051/selfhotel.h
7. The header file defining the methods in the base class
See
http://www.wellho.net/resources/ex.php4?item=c051/g_hotel.h
In essence, C++ is mostly about adding object orientation to C (thus meking it a completely different kettle of fish!), so I have loaded each of the course files above onto our web site so that you can see the complete example under the category "C++ in general". They illustrate a very large range of features - inheritance, overloading, polymorphism, virtual functions, etc ... all of which I'll explain to you on our C++ courses - in fact, this set of examples was written on the C++ course which ended yesterday, where I showed the delegate how we design and write object oriented programs in C++ from scratch.
We offer three public courses
Learning to program in C++ - 5 days, for delegates who have never programmed before in any programming language, or have done so VERY little.
See
http://www.wellho.net/course/cffull.html
C and C++ programming - 4 days, for delegates who have programmed before, but not in C (on which C++ is based)
See
http://www.wellho.net/course/cafull.html
C++ Programming - 2 days, for experienced C programmers who need to add the extras of C++ (and learn which parts of C they can gently retire!)
See
http://www.wellho.net/course/cpfull.html (written 2010-01-15 09:07:59)
Associated topics are indexed under
C051 - C and C based languages - C++ - General [2851] Further C++ material - view new or old - (2010-07-04)
[2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
[2536] All the Cs ... and Java too - (2009-12-13)
[2504] Learning to program in ... - (2009-11-15)
[2370] C++, Python, and other training - do we use an IDE - (2009-08-21)
C233 - C and C based languages - OO in C++ - beyond the basics [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
[1819] Calling base class constructors - (2008-10-03)
[1674] What a lot of files! (C++ / Polymorphism demo) - (2008-06-12)
[1572] C - structs and unions, C++ classes and polymorphism - (2008-03-13)
[1217] What are factory and singleton classes? - (2007-06-04)
[925] C++ - just beyond the basics. More you can do - (2006-11-14)
[831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
[801] Simple polymorphism example - C++ - (2006-07-14)
[798] References and Pointers in C++ - (2006-07-10)
C232 - C and C based languages - Defining and using classes in C++ [2579] Creating, setting up and using objects in C++ - (2010-01-16)
[2578] Where are your objects stored in C++? - (2010-01-16)
[1925] Introduction to Object Oriented Programming - (2008-12-06)
Some other Articles
Snow scenes - and how snow effected our businessC course inspires new teaching examplesComplete teaching example - C++, inheritance, polymorphismWhat does const mean? C and C++Sharing variables between files of code in C - externSummary of Wiltshire Core Strategy responsesC Structs - what, how and whyThe what and why of C pointers