FRIEND FUNCTION
A non member function may not possess an access to the private data of a class . But , there could possibly be a scenario in which we want two classes to share a specific function . To illustrate , take into account a case where two classes , supervisor and Warden , are defined . We want to use a function Salary( ) to work on the object of both these classes...
Tuesday
//
Labels:
c++
//
0
comments
//
One among the objectives of OOP is to standalone the details of execution from the class definition . It can be therefore a good idea to define the member functions outside the class . You can easliy define a member function outside the class definition yet still allow it to be inline just by making use of the qualifier inline in the header line of the function definition .For eg.
class box{............public:void...
Tuesday
//
Labels:
c++
//
0
comments
//
OBJECTS
When the class is formed , a number of objects may be created from the class as objects are illustration of the class .Objects are the physical entity to represent classes .A class gives you the blueprints for objects , thus generally an object is formed from a class . We declare objects of a class with precisely the same kind of declaration that we declare variables of fundamental types...
Tuesday
//
Labels:
c++
//
0
comments
//
Concept of classes and objects run side by side.Hence,its beneficial if we discuss the duo together.
A class is an extended prospect of a data structure : rather than keeping just data , it may possess both data and functions .An object is an instantiation of a class . When it comes to variables , a class can be the type , as well as an object would be the variable .
Format for declaring a class:
class...
Tuesday
//
Labels:
c++
//
0
comments
//
INLINE FUNCTIONS
C++ inline function is an effective concept which is commonly used with classes. If a function is inline, the compiler stores a copy of the code of the function at every point exactly where the function is called at compile time.Any kind of change to an inline function might require all clients of the function to be recompiled simply because compiler might need to change all the code once again elsewhere it will continue with old functionality.To inline a function, place the...
Monday
//
Labels:
c++
//
0
comments
//
Functions can be called in two ways:-
1)Call by reference
2)Call by value
1)Call by value
Call by value is just calling a function simply.Call by value simply copies the values of the arguments in the formal parameters.For eg.
#include <iostream.h>
int ADD(int m);
int main(void)
{
int n= 50;
cout<<"%d %d"<< ADD (n), n);
return 0;
}
int ADD (int n)
{
n = n + n;
return n;
}
2)Call by refrence
Whenever you declare a variable in a...
Tuesday
//
Labels:
c++
//
0
comments
//
A function is a collection of statements that collectively operate a task. Every single C++ program includes a minimum of one function that is main(), and all the the majority of small programs can define other functions.
You may split up your code into different functions. A function name employs the similar rules that have been employed on our variables until now .Further to this,make use of a name that specifies exactly what the function |is predicted to do.
FUNCTION DECLARATION
In...
Monday
//
Labels:
c++
//
0
comments
//
Object oriented programming deals with partitioning the entire programs into groups using data structures called 'objects' and assigning attributes and methods to them.Object oriented programming consists of two things:
1) classes
2) objects
CLASSES:
A class is a group of attributes of the same kind. it is used to impart object orientedness to a program. for example,pen, pencil, rubber etc belongs to a class stationary.A class is a blueprint for a data type. it cant be implemented itself, we...
Wednesday
//
Labels:
c++
//
0
comments
//
Variables are certain data types which can store values during execution of the program.The values stored in variables can be changed during the program execution.For eg. a,b,d etc.
Declaration of Variables
In order to create use of a variable in C++, they need to first declare it specifying which data type they need it to be. The syntax to declare a new variable is to write the specifier of the specified data type (like...
Wednesday
//
Labels:
c++
//
0
comments
//
SAMPLE PROGRAM FOR BEGINNERS
// sample program
#include <iostream>
using namespace std;
int main ()
{
cout << "This is my first program";
return 0;
}
// sample program
This is a comment line. All lines starting with slash signs (//) are comments and don't have any impact on the behavior of the program. The computer programmer will use them to incorporate short explanations...
Friday
//
Labels:
c++
//
0
comments
//
Powered by Blogger.