Problems with an addition operator
I am wondering if anyone can help me, I fairly new to C++ and am trying to implement an addition operator that acceptsan object based on another class as a parameter. I have tried a few things, but I fear I am way off base. My code worked up until the point of implementing the addition operator.
If anyone could help or give me a push in the right direction I would really appreciate it!
<code>
//first class
#include <iostream>
using namespace std;
class Course
{
public:
Course(string nameValue, int yearValue);
Course(int yearValue);
Course();
//my not working addition operator
const Course operator +(const Course& vEnrol, const Course& vcost);
void output();
private:
int vCost;
int vEnrol;
int year;
string name;
};
//my second class
#include <iostream>
using namespace std;
class Enrolment
{
public:
Enrolment(int enrolValue, int costValue);
private:
int cost;
int enrol;
};
//main
#include <iostream>
#include <string>
#include "Course.h"
#include "Enrolment.h"
using namespace std;
int main(int argc, char* argv[])
{
Course a("English", 2003);
Course b("Maths", 2003);
// initialising the Enrolment constructor
Enrolment(0,0);
cout<< "Before Enrolments:" << endl;
a.output();
b.output();
//This part does not work
a = a + Enrolment(50, 500);
a = a + Enrolment(20, 200);
cout<< "After Enrolment:" << endl;
cout<< "=================" << endl;
a.output();
b.output();
return(0);
}
Course::Course(string name_, int year_)
: class(name_), year(year_)
{
}
Enrolment::Enrolment(int enrol_, int cost_)
: enrol(enrol_), cost(cost_)
{
}
//test addition operator
const Course operator +(const Course& vEnrol, const Course& vcost)
{
int vEnrol = vEnrol + Enrolment.enrol;
int vcost = vcost + Enrolment.cost;
return Enrolment(venrol, vcost);
}
void Course::output()
{
cout<<"Course: "<<name<<" "<<year<< endl;
cout<< "Total enrolement :" <<venrol<<endl;
cout<<"Total Income : "<<vcost<<endl;
cout<<endl;
}
</code>