More Definitions

A concrete data type is a class whose objects behave like variables of native data types. That is, the class gives the compiler enough information that its objects can be created, copied, assigned, and automatically destroyed just as native variables are. The StockItem class that we will construct in this chapter is a concrete data type.

A constructor is a member function that creates new variables of the class to which it belongs. All constructors have the same name as the class for which they are constructors; therefore, the constructors for StockItem variables also have the name StockItem.

A default constructor is a constructor that is used when no initial value is specified for an object. Because it is a constructor, it has the same name as the class; since it is used when no initial value is specified, it has no arguments. Thus, StockItem() is the default constructor for the StockItem class.

A copy constructor is a constructor that makes a new object with the same contents as an existing object of the same type.

An assignment operator is a member function that sets a pre-existing object to the same value as another object of the same type.

A destructor is a member function that cleans up when an object expires; for a local object, this occurs at the end of the block where that object is defined.

The object member access operator is “.” (period). It separates an object name, on its left, from the member variable or member function on its right.

::, when used immediately after a class name, is the class membership operator, which indicates the class a variable or function belongs to.[7]

[7] :: is the scope resolution operator when it does not follow a class or namespace name. This is another example of the confusing tendency of C++ to reuse the same sequence of characters to mean something different.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset