I have a class called ParkingLot with a function called removeCarsThatWantToLeave and I declared this function a friend of my Space class so that removeCarsThatWantToLeave can have access to the occupyingCar pointer that is a member of Space
This is the function in ParkingLot.cpp that I'm working on but my compiler shows a red squiggly line under .occupyingCar and says it is inaccessible
/*
Description: iterates through the array of parking spaces
and destroys the cars that have been parked as long as the amount
of time specified in their minutesToPark member
Return: void
*/
void ParkingLot::removeCarsThatWantToLeave(int curTime)
{
int timeParked; //amount of time car in a space has been parked
//this is a temp variable that will be used
//for the time parked of all cars in the lot
for (int i = 0; i < numParkingSpaces; i++)
{
timeParked = parkingSpaceArray[i].occupyingCar->
//if (parkingSpaceArray[i].occupyingCar->
{
}
#pragma once
#include <iostream>
#include <list>
//forward declarations
class Car;
class Space;
usingnamespace std;
class ParkingLot
{
private:
//making this a singleton because there will be only one parking lot and
//it will make global access to the parking lot easier. It won't need to be
//passed between functions a lot this way.
static ParkingLot* parkingLotInstance;
//will use array because I won't need to change
//the number of parking spaces there are
Space* parkingSpaceArray;
bool isFull;
int numParkingSpaces;
int numFilledParkingSpaces;
public:
ParkingLot(void);
static ParkingLot* getInstanceOfParkingLot();
//returns index of the first empty parking space in the array
//called by Car::parkCar
int getIndexOfFirstEmptyParkingSpace();
void addCarToParkingSpaceArray(int indexOfEmptyParkingSpace, Car* carToAdd);
void removeCarsThatWantToLeave(int curTime);
//setters
void setNumParkingSpaces(int n);
void setNumFilledParkingSpaces(int n);
//getters
bool getIsFull();
int getNumParkingSpaces();
int getNumFilledParkingSpaces();
~ParkingLot(void);
};
#include "Car.h"
#include "Space.h"
#pragma once
class Car;
usingnamespace std;
class Space
{
private:
//need this because I shouldn't just check whether occupyingCar points to null
//since that would involve a public method returning a pointer to a private member
bool isOccupied;
int minutesPurchased;
Car* occupyingCar; //pointer to car that occupies this space
public:
Space(void);
//friend
friendvoid ParkingLot::removeCarsThatWantToLeave(int curTime);
//setters
void setIsOccupied(bool i);
void setMinutesPurchased(int m);
void setOccupyingCar(Car o);
//getters
bool getIsOccupied();
int getMinutesPurchased();
~Space(void);
};
#include "Car.h"