Write a program to subtract two time objects and stored the result in 3rd object using operator member function and friend function
#include <iostream>
using namespace std;
class objectB;
class objectA {
public:
objectA() : nA(12) {}
private:
int nA;
friend int subtract(objectA, objectB);
};
class objectB {
public:
objectB() : nB(6) {}
private:
int nB;
friend int subtract(objectA, objectB);
};
class objectC{
friend int subtract(objectA, objectB);
};
int subtract(objectA objA, objectB objB) {
return (objA.nA - objB.nB);
}
int main() {
objectA objA;
objectB objB;
cout << "Result in 3rd object is: " << subtract(objA, objB);
return 0;
}
Comments
Leave a comment