#include <iostream> using namespace std; class Example { int a; public: void setval(int x); int addval(Example &ex); }; void Example::setval(int x) { a=x; } int Example::addval(Example &ex) { int c; c=ex.a+a; return c; } int main() { Example obj1,obj2; int sum; obj1.setval(10); obj2.setval(20); sum=obj1.addval(obj2); cout<<" the sum is :"<<sum<<endl; }
Output : $g++ -o main *.cpp $main the sum is :30
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)