Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
You are currently on our new server (weekend of 19th/20th July). See here.
C++ - 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-> if you want to use the same variable name for a parameter to the method (or as a local variable within it)

3. You can declare a destructor method (which has the same name as the class name preceeded by a ~ - a tilde) which is code to be run when you've finished with an object, and before the program finishes

4. You can have two methods of the same name but with a different 'pattern' of parameters, and your program will work out which is the one you're calling in each case. This is similar to polymorphism ... but not actually polymorphism; Polymorphism IS supported by C++ as well!

These are all just slightly beyond the first basics, and you certainly won't use ALL of them in a single program (unless you're doing a class excercise as I was yesterday!) Here are sample declarations for three of these techniques:

class MSheet {
 public:
  MSheet(float ecs, float why);
  MSheet(float ecs); // No. 4 - 2 methods of same name
  ~MSheet(); // No. 3 - destructor
  void setx(float size);
  void sety(float size) ;
  float getarea() const; // No. 1 - const
 private:
  float x;
  float y;
 };


and for "this":

MSheet::MSheet(float x, float yy) {
 this->x = x; // No. 2 - this

(written 2006-11-14 00:05:36)

 
Associated topics are indexed under
C233 - C and C based languages - OO in C++ - beyond the basics
C239 - C and C based languages - Putting it all together

Back to
The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl
Previous and next
or
Horse's mouth home
Forward to
Training rooms to learn Open Source programming

Some other Articles
Presenting Melksham - for a weekend away in Wiltshire
C++ and Perl - why did they do it THAT way?
Hotel door furniture
Training rooms to learn Open Source programming
C++ - just beyond the basics. More you can do
The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl
Why shouldn't I spam?
Staying at your own hotel
French Exchange
A lion in a cage - PHP
1705 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 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).

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