*Define the following words used in C++. Class prototype: Class methods: Class d
ID: 671175 • Letter: #
Question
*Define the following words used in C++.
Class prototype:
Class methods:
Class data:
Class access privileges:
Class direct instance:
Class indirect instance:
Class constructor:
Class destructor:
Named object:
Object Pointer:
New:
Malloc:
MinGW32:
Code::Blocks:
C++:
C++11:
wxWidgets:
Standard library:
Namespaces:
using:
istream:
ostream:
scope operator:
function definition:
function overloading:
operator overloading:
dereference a named object member:
dereference an object pointer member:
overloading:
call-by-reference:
call-by-value:
direct instance:
indirect instance:
member declaration:
member definition:
dot operator:
arrow operator:
class prototype:
scope operator:
Explanation / Answer
Class prototype:
You can declare all your classes and then define them in any order, like so:
Class methods:
A member function of a class is a function that has its definition or its prototype within the class definition like any other variable. It operates on any object of the class of which it is a member, and has access to all the members of a class for that object.
Member functions can be defined within the class definition or separately usingscope resolution operator, ::. Defining a member function within the class definition declares the function inline, even if you do not use the inline specifier. So either you can define Volume() function as below:
Class data:
A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations. For example, we defined the Box data type using the keyword class as follows:
Class access privileges:
You have access privileges in C++ such as public, protected and private that helps in encapsulation of data at various level.
Private
If data are declared as private in a class then it is accessible by the member functions of the class where they are declared. The private member functions can be accessed only by the members of the class. By default, any member of the class is considered as private by the C++ compiler, if no specifier is declared for the member.
Public
The member functions with public access specifier can be accessed outside of the class. This kind of members is accessed by creating instance of the class.
Protected
Protected members are accessible by the class itself and it's sub-classes. The members with protected specifier act exactly like private as long as they are referenced within the class or from the instance of the class. This specifier specially used when you need to use inheritance facility of C++.
Class constructor:
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.
Class destructor:
A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.
A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
Named object:
A class provides the blueprints for objects, so basically an object is created from a class. We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types. Following statements declare two objects of class Box:
Both of the objects Box1 and Box2 will have their own copy of data members.
Object Pointer:
A pointer to a C++ class is done exactly the same way as a pointer to a structure and to access members of a pointer to a class you use the member access operator -> operator, just as you do with pointers to structures. Also as with all pointers, you must initialize the pointer before using it.
Let us try the following example to understand the concept of pointer to a class:
When the above code is compiled and executed, it produces the following result:
New:
Allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the object.
Syntax:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.