Last lesson, we created a class and all of its member functions. This short lesson will describe how to use it. The first oddity is how you declare an instance of your class and what you can do within it. In lieu of a suitable explanation, I'll simply show you.
This is it. After this line, the default constructor will have executed, leaving myDB's myID member set to 0 and its myName member set to "". Admittedly, this isn't the odd part. The odd part comes into play with any custom constructors you have have. The one I created will be called as such.
As you can see, you simply place the parenteheses & parameter list in front of the variable name as though it were a function. As I mentioned earlier, this method calls the custom constructor with a matching set of arguments. After it executes, My2ndDB's myID member equals 1 and its myName member equals "Ryan".
Finally, we have the copy constructor. This one is only necessary if you want to be able to create a copy of a class, or set one equal to another. To use it, simply set a variable of class Database equal to another Database variable's declaration, like so.
Database my3rdDB = my2ndDB;
After this, the copy constructor will have been called and my3rdDB will be a copy of my2ndDB.
Next, we'll just make a few calls using these three Database variables to demonstrate their usage.
myDB.setID(5); myDB.setName("John"); cout << my2ndDB.getName() << " has the ID " << my2ndDB.getID() << endl;
I could go on, but I think this sufficiently describes their functionality.