I’ve been instructed to create two Classes: Customer and Barber,
Barber should have a function : cutHair() that can change the value of private member hairLength in Customer.
Customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include "barber.h"
#include <iostream>
#include <string>
using namespace std;
class Customer{
public:
friend void Barber::cutHair(Customer &someGuy);
Customer(string name, double hairLength);
string getName();
double getHair();
void setHair(double newHair);
private:
string name;
double hairLength;
};
#endif
Barber.h
#ifndef BARBER_H
#define BARBER_H
#include <iostream>
#include <string>
#include "customer.h"
using namespace std;
class Customer;
class Barber{
public:
Barber(string barberName);
void cutHair(Customer &someGuy);
private:
string name;
double takings;
};
#endif
barber.cpp EDIT: I changed the implementation of cutHair() to take advantage of the friend declaration instead of accessing the private members of class Customer through it’s public accessor methods
#include "barber.h"
#include <string>
Barber::Barber(string barberName){
name = barberName;
takings = 0;
}
void Barber::cutHair(Customer &someGuy){
takings += 18;
someGuy.hairLength = someGuy.hairLength * 80 / 100;
}
customer.cpp
#include "customer.h"
#include <string>
Customer::Customer(string customerName, double custHairLength){
name = customerName;
hairLength = custHairLength;
}
double Customer::getHair(){
return hairLength;
}
void Customer::setHair(double newLength){
hairLength = newLength;
}
when attemping to build i get the error message
customer.h(10): error C2653: 'Barber' : is not a class or namespace name
been doing research and canceling out issues one after another for a few days now.
hope someone can come to my rescue 🙂
In
Barber.hyou are forward declaring Customer (class Customer;) AND including#include Customer.h". Try removing the include. Of course you will have to add the include in yourBarber.cpp