Yes folks me again, but if I don't struggle through, I don't learn it. I'm constructing my main (no interactivity at this point), and when I start to declare/create my first object, it doesn't like the string portion of the input and tells me this:
error C2664: 'Contributor::Contributor(std::string,double,gender,int)' : cannot convert parameter 1 from 'Contributor *' to 'std::string'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Now I realize this points to a problem with one of my constructors (either the overload or the copy) but not sure which, nor what the problem is. Code follows:
HEADER
#pragma once
#include <string>
#include <iostream>
using namespace std;
enum gender {none,male,female};
class Contributor
{
public:
Contributor();
Contributor (string Name, double Donation =0.0, gender sex=none, int IDKey=0);
Contributor (const Contributor& CCContributor);
~Contributor();
friend ostream& operator << (ostream& out, const Contributor& InContributor);
friend istream& operator >> (istream& in, Contributor& InContributor);
Contributor& operator = (const Contributor& rhs);
bool operator < (const Contributor& rhs)const;
bool operator > (const Contributor& rhs)const;
bool operator == (const Contributor& rhs)const;
bool operator != (const Contributor& rhs)const;
private:
string Name;
double Donation;
int IDKey;
gender Sex;
};
CLASS DEF CPP
#include "Contributor class.h"
Contributor::Contributor()
{
Donation=0.0;
Sex=none;
IDKey=0;
}
Contributor::Contributor (std::string Name, double Donation, gender Sex, int IDKey)
{
this->Name=Name;
this->Donation=Donation;
this->Sex=Sex;
this->IDKey=IDKey;
}
Contributor::Contributor (const Contributor& CCContributor)
{
Name=CCContributor.Name;
Donation=CCContributor.Donation;
Sex=CCContributor.Sex;
IDKey=CCContributor.IDKey;
}
Contributor::~Contributor()
{
cout<< "I have cleaned up yer mess" << endl;
}
ostream& operator << (ostream& out, const Contributor& InContributor)
{
out << "The Contributor's information is: " << endl << endl;
out << " Name: " << InContributor.Name << endl;
out << " Donation: " << InContributor.Donation << endl;
out << " Sex: ";
switch (InContributor.Sex)
{
case male: out << " Male "; break;
case female: out << " Female "; break;
default: out << " No information available ";
}
out << endl;
return out;
out << " IDKey: " << InContributor.IDKey << endl;
}
istream& operator >> (istream& in, Contributor& InContributor)
{
int sel=0;
in.clear();
in.ignore(in.rdbuf()->in_avail(),'\n');
cout << "Please enter the name of the contributor: "<<endl;
getline (in, InContributor.Name);
cout << "Please enter the amount of the donation from the contributor: "<<endl;
in >> InContributor.Donation;
cout << "Please enter number of the sex of the contributor: "<<endl << endl;
cout << "1 = The Contributor is male"<<endl;
cout << "2 = The Contributor is female "<<endl;
in >> sel;
switch (sel)
{
case 1: InContributor.Sex = male; break;
case 2: InContributor.Sex = female; break;
default: InContributor.Sex = none; break;
}
cout << "Please enter the ID Key of the contributor: "<<endl;
in >> InContributor.IDKey;
return in;
}
Contributor& Contributor::operator = (const Contributor& rhs)
{
if (&rhs != this)
{
this->Name=Name;
this->Donation=Donation;
this->Sex=Sex;
this->IDKey=IDKey;
}
return *this;
}
bool Contributor::operator < (const Contributor& rhs)const
{
if (Name < rhs.Name)
return true;
else
return false;
}
bool Contributor::operator > (const Contributor& rhs)const
{
if (Name < rhs.Name)
return true;
else
return false;
}
bool Contributor::operator == (const Contributor& rhs)const
{
if ((Name,Donation,Sex,IDKey)==(rhs.Name,rhs.Donation,rhs.Sex,rhs.IDKey))
return true;
else
return false;
}
bool Contributor::operator != (const Contributor& rhs)const
{
return ! (*this == rhs);
}
MAIN CPP (so far)
#include "Contributor Class.h"
int main()
{
Contributor *Jerry;
Jerry = new Contributor(Jerry,500.00,male,1);
return 0;
}