Method Chaining.
ob.fun1().fun2():
The below example is to illustrate the Method Chaining.
Eg:
=================================================================
class A
{
int x;
public:
A() {x=10; }
int getX() { return x;}
};
class B
{
int y;
public:
B() { y=20; }
A fun2();
};
A B::fun2()
{
A o;
return o;
}
int main()
{
A ob;
B ob2;
cout<< ob2.fun2().getX() ;
return 0;
}
=================================================================
Output:
10
Comments
Eg:
==============================
class A
{
int x;
public:
A() {x=10; }
int getX() { return x;}
};
class B
{
int y;
public:
B() { y=20; }
A fun2();
};
A B::fun2()
{
A o;
return o;
}
int main()
{
A ob;
B ob2;
cout<< ob2.fun2().getX();
return 0;
}
==============================
10