Sum of Two Objects

#include <iostream>
using namespace std;

class Distance;  // forward declaration

class Point {
 private:
 int x;

 public:
  Point(int v) : x(v) {}
  	// your code here: declare friend function sumValues
  friend void sumValues(const Point& a, const Distance& b);
};

class Distance {
 private:
 	int d;

 public:
 	Distance(int v) : d(v) {}
 	// your code here: declare friend function sumValues
	// friend int sumValues();
    friend void sumValues(const Point& a, const Distance& b);

};

// your code here: define friend function sumValues
void sumValues(const Point& a, const Distance& b){
	cout << "Sum="<<a.x + b.d<<endl;
}


int main() {
	int a, b;
	cin >> a >> b;
	
	Point p(a);
	Distance dist(b);

	sumValues(p, dist);
	return 0;
}
Upvote
Downvote
Loading...

Input

5 7

Expected Output

Sum=12