Would somebody mind looking at this code and giving me some advice as to the copy constructor and assignment operator overload function? When I try to use this class in my program, I get the following error:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Person *' (or there is no acceptable conversion)
header file:
#ifndef Person_H
#define Person_H
// Class Name: Person
// Class Language: C++
// Class Filename: Person.h
class Person {
// Attributes:
private:
// private data members:
int ID;
int personCount;
int weight;
int waitTime;
// Operations:
public:
// public member functions:
Person();
~Person();
Person(const Person& aPerson);
Person &operator=(const Person &right);
void PersonLeavesBuilding();
};
#endif // Person_H
#include <stdlib.h>
#include <stdio.h>
#include "Person.h" // class header file
#include "building.h"
Person::Person()
{
personCount++;
ID=personCount;
waitTime=(1+rand()%100);
}
Person::Person(const Person& aPerson) {
ID=aPerson.ID;
personCount=aPerson.personCount;
waitTime=aPerson.waitTime;
weight=aPerson.weight;
}
Person &Person::operator=(const Person &right) {
if (&right != this) {
ID=right.ID;
personCount=right.personCount;
waitTime=right.waitTime;
weight=right.weight;
}
return (*this);
}
void Person::PersonLeavesBuilding() {
personCount--;
}
This is fairly new to me so any suggestions would be more than appreciated!
thanks!