This topic is really hard for me to grasp. I tried making a program to test out operator overloading and I can't seem to get it to work.
#ifndef TESTCLASS
#define TESTCLASS
using namespace std;
class testClass
{
public:
testClass(double, double);
friend testClass operator+(testClass& a, testClass& b);
private:
double num1, num2;
};
testClass::testClass(double numA, double numB)
{
num1 = numA;
num2 = numB;
}
testClass operator+(testClass& a, testClass& b)
{
return(a.num1 + b.num1, a.num2 + b.num2);
}
#endif
#include <iostream>
#include "testClass.h"
#include <string>
using namespace std;
int main()
{
testClass obj1(1.1,2.2);
testClass obj2(2.2,3.3);
testClass obj3;
obj3 = obj1 + obj2;
cout << obj3 << endl;
return 0;
}
I'm really lost.