Skip to main content

Posts

Concept of friend function in opp with c++

#include <iostream> using namespace std; class B; class A { int a; public:     void set_val (int x ){ a=x;     }     friend void add(A,B); }; class B{ int b; public:       friend void add (A,B); void set_val (int y ){ b=y; } }; void  add (A obj1, B obj2) {        cout <<  "The Sum  is "  <<  obj1.a+obj2.b << endl; } int main() {     A obj;     B o;     obj.set_val (500); o.set_val(220); add(obj,o);     return 0; }

Introduction to Functions and Function overloading

Objective: Concept of following ·          Functions by value. ·          Function by Argument. ·          Function Overloading. Software : Code blocks. Theory: Functions &Function Overloading Function is very useful concept in programming. It helps to save time and effort also, Function divided into three categories: ·          Prototype.   ·          Function calling. ·          Function definition. Function Definition Syntax:    Data_Type Function Name ( ){ Function definition . Return (According to data type) } Function overloading: Function overloading  is a programming concept that allows programmers to define two or more functions with the same name and in the same scope .  ...