Generally we access a member function (say fun1()) of a class(say ClassA) as-
1. ClassA a; //Declare object of ClassA
2. a.fun1(); //It means fun1() is defined inside ClassA
But somewhere I have seen codes like -
3.a.fun1().fun2(); //But a function can never be defined inside a function.
For example in C# I can write-
4. string query = "select * from Hindi";
5. query.Trim().ToString();
So what is the concept behind code of line 3 or 5(callinga function by a function). Please provide any sample examples in c++.
class B
{
public:
B& CallMe(int foo)
{
// do something
return *this;
}
};
int main()
{
B b;
// now this...
b.CallMe(1).CallMe(2);
// is the same as this:
b.CallMe(1);
b.CallMe(2);
}
Note that this is exactly how the << operator works with cout/iostream.