Академический Документы
Профессиональный Документы
Культура Документы
CONSTANT FUNCTIONS
OUTPUT:11
the class.
The keyword const is placed between the
<return type> <function name> (argument 1,argument 2,.) const { <the function body> }
#include<iostream.h> #include<conio.h> class sample { public: int a; void disp() const { cout<<++a; } };
Data members cannot be modified by the const function. If a data member is declared as mutable the it can be even modified by const function.
Syntax:
mutable data_type variable_name; mutable int a;
#include<iostream.h> #include<conio.h> class sample { public: mutable int a; void disp() const { cout<<++a; } };
VOLATILE FUNCTIONS
as volatile if it is
An object taking input from NIC does not take input from our program .As and when hardware interrupts the value related to change without our programs knowledge.
class B { int x; public: void f() volatile; // volatile member function }; void main() { volatile B b; // b is a volatile object b.f(); // call a volatile member function safely }