Take the following Seat class:
class Seat
{
Passenger* passenger; // I'd like this to be Passenger passenger;
}
If I remove the asterisk, how should I update the following method?
bool initSeat()
{
passenger = NULL; // &passenger = NULL; does not compile as it's not a reference type.
return passenger == NULL; // Is there even a need to allocate memory? Maybe have the method blank?
}
and
bool insertSeat(Passenger* p)
{
bool bsuccess = TRUE;
if (p != NULL)
{
if (passenger == NULL) // replace with &passenger
passenger = p; // replacing with &passenger doesn't compile
else
bsuccess = FALSE;
}
else
passenger = NULL; // again, prefixing the & doesn't compile (that'd make it a reference type) so how do I set the pointer to NULL?
return bsuccess;
}
I might be confused because I am missing some basic concept.