Can you explain it to me, I've done the exercises but all I did was pattern it from the book and I only understood few of the concepts.And also "arguments"
Printable View
Can you explain it to me, I've done the exercises but all I did was pattern it from the book and I only understood few of the concepts.And also "arguments"
Concerning arguments, do you know how to write simple functions? Constructors (and member functions) use arguments in the same way.
As for the rest, you might show some code and ask more specifically what you don't understand.
Construction is a form of initialization, they help create objects of a class. It's actually a special function within the class.
Private data members make up the inner workings of a class. For example (cliché, i know), let's say you wanted to make a class that models a car. A car must have an engine in order to work. However, regular drivers shouldn't have to know how the engine works in order to operate the car. All you have to do is put the key in the ignition and start the car. This design would like so:
The public members of a class make up what is sometimes called the public interface of that class, because those members are what the outside world uses in order to operate that class.Code:class Engine;
class Car
{
private:
Engine engine; // This is a private engine...
// Only the car itself knows about the greasy inner workings of the engine.
public:
void ignition_start() // This function is public... this is how people start the car.
{
engine.turnOn(); // They DON'T have to pop the hood and start the engine manually!
}
};
In essence, private members can only be seen and used from within the class itself.