Returning Objects from Function in C++
In this tutorial you will learn:
1. How to pass an object in a function argument
2. How to return an object from a function
3. How to write functions outside class
4. Basic C++ syntax
In C++ when we need to return a variable from a function we have to write its return type before the name of function and arguments. As class can also be thought of as a type of object so in C++ we can also return whole object from a function.
Object of class ‘myClass’ can be returned from a function as follow