+ 2
How to return function from an object and why we use that in c++?
5 Answers
+ 7
#include <iostream>
using namespace std;
class ccc
{
public:
int a,b;
ccc func(int a,int b)//function returning object
{
ccc y;
y.a=a;
y.b=b;
return y;
}
};
int main() {
ccc p;
p=p.func(5,6);//function calling
cout<<p.a<<p.b;
return 0;
}
+ 3
To show the result. For example, if you have an add function, you want to know its result.
int add(const int a, const int b)
{
return a + b;
}
+ 2
Do you mean returning an object from a function?
+ 1
yes that is the correct, that is what I mean
+ 1
I mean in class I read this but didn't understand https://www.programiz.com/cpp-programming/pass-return-object-function