> 1) the setDriver method, am I getting input from user? I don't understand
> what the instructions are saying & hoe do I update the driver without
> creating a new driver?
> including a setDriver method that takes a firstName, lastName, and Address
> and updates the driver to those values
use the setters
1 2 3 4 5
|
//pseudocode
def setDriver(firstName, lastName, address):
this.driver.set_firstName(firstName)
this.driver.set_lastName(lastName)
this.driver.set_address(address)
|
what do you pass to that function is up to you
some_car.setDriver("Null", "Nameless", "Under the bridge");
> 2) the copy constructor
first, ¿why a Car has a pointer to a Person?
I initially though that the idea was to have something like
1 2 3 4 5
|
Person teacher;
Car pinto;
pinto.setDriver(&teacher);
pinto.crash(); //the driver died, so now the teacher is dead
teacher.isDead(); //true
|
but as how the Car
creates a new Person it seems that's just added complexity for the sake of it. (you'll also need a proper destructor)
Now, look at your attempt.
1 2 3 4 5 6 7
|
Car(const Car &other) :
make(other.make),
color(other.color),
year(other.year)
{
this->driver = new std::string();
}
|
a driver is a pointer to a Person, ¿why are you doing
new std::string()
then?
just call the Person copy constructor
1 2 3 4 5 6
|
Car(const Car &other) :
make(other.make),
color(other.color),
year(other.year),
driver(new Person(*other.driver))
{}
|
> << operator (insertion)
this is << for printing, not < for comparison
outside the Car class define the function
1 2 3 4 5 6 7 8
|
std::ostream& operator<<(std::ostream &output, const Car &c){
//example implementation
if(c.getColor() == "black")
output << "An invisible car";
else
output << "A " << c.getColor() << " car";
return output;
}
|