Hi everyone,
I'm trying to learn C++ and about pointers and whatnot and seem to be a bit stuck... one of the exercises we were given involves passing an object (a Driver object) by reference to another object (a Manufacturer), which stores it. The Manufacturer object can then "employ" and "release" a Driver, but I can't seem to get my head around the way the pointers and that work :S
Any help would be much appreciated, and thank you in advance!!!
#include <iostream>
#include <string>
using namespace std;
class Driver
{
public :
Driver(string fn, string sn) : firstname(fn), surname(sn)
{
}
~Driver()
{
}
private :
string firstname, surname;
};
class Manufacturer
{
public :
Manufacturer(string n) : name(n)
{
}
~Manufacturer()
{
}
void Employ(Driver d)
{
if(driver1 == 0)
driver1 = d;
else if (driver2 == 0)
driver2 = d;
}
void Release(Driver d)
{
if(driver1 == d)
driver1 = 0;
else if (driver2 == d)
driver2 = 0;
}
void WhatIsYourTeam()
{
}
private :
string name;
Driver driver1;
Driver driver2;
};
int main()
{
Driver M_Schumacher("Michael", "Schumacher");
Driver R_Schumacher("Ralph", "Schumacher");
Driver J_Button("Jenson", "Button");
Driver E_Irvine("Eddie", "Irvine");
Manufacturer ferrari("Ferrari");
Manufacturer williams("Williams");
ferrari.Employ(&M_Schumacher);
ferrari.Employ(&E_Irvine);
williams.Employ(&R_Schumacher);
williams.Employ(&J_Button);
ferrari.WhatIsYourTeam();
williams.WhatIsYourTeam();
// change teams
ferrari.Release(&E_Irvine);
williams.Release(&J_Button);
ferrari.Employ(&J_Button);
williams.Employ(&E_Irvine);
ferrari.WhatIsYourTeam();
williams.WhatIsYourTeam();
return 0;
}