My Professor gave us this class and told us that it won’t compile. He says that the donors array would conflict with the constructor. So… why would that be?
I think that the name of the Donor array might do it, but it shouldn’t be the problem because the name of the member array donor is case sensitive, and is therefore different than the class name.
Here’s the code:
#ifndef DONORS_H
#define DONORS_H
#include <string>
#include "name.h"
#include "donor.h"
using namespace std;
const int
DONORS_LOAD_ERROR = 1,
DONORS_UPDATE_ERROR = 2,
DONORS_ADD_ERROR = 3;
const int MAX_DONORS = 100;
class Donors {
public:
Donors() : size(0) {}
void load(string filename);
int getSize() {return size;}
int find(Name name);
int add(Name name);
int add(Name name, Donation donation, int ytd);
void processDonation(Name name, Donation donation);
void update(string filename);
void print();
private:
Donor donorsList[MAX_DONORS];
int size;
};
#endif
The professor writes:
In this version, we’ve taken version 2, added constructors, and maximized the use of objects.
HOWEVER, the introduction of constructors breaks the declaration of the array data member inside the Donors class;
therefore THIS VERSION DOES NOT COMPILE!!!!
I’ve been discussing this with a classmate and we’re both stumped. What’s up with this C++ class?
Edit:
The compiler messages are shown below:

It just occurred to me that the Donor class has a constructor. Being that we haven’t touched vectors with a ten foot pole, how on earth are we supposed to compile this?
Edit2:
Here’s the donor class:
#ifndef DONOR_H
#define DONOR_H
#include "name.h"
#include "donation.h"
using namespace std;
class Donor {
public:
Donor(Name n, Donation ld=Donation(0, 0), int y=0) : name(n), lastDonation(ld), ytd(y) {}
Name getName() {return name;}
Donation getLastDonation() {return lastDonation;}
int getYtd() {return ytd;}
void processDonation(Donation d);
private:
Name name;
Donation lastDonation;
int ytd;
};
#endif
Difficult to say without the definition of the
Donorclass, but my guess is that he added a constructor with parameters to theDonorclass, so it won’t have the implicit default constructor any more.But now, without a default constructor, that is a constructor that can be called without arguments, you cannot declare an array of such type, because there is no way to pass on the required parameters!