E
EM.Bateman
Working on Visual Studio .Net I've implemented a class:
#ifndef CONTRIBUTOR_H
#define CONTRIBUTOR_H
enum Gender {male=1, female, unk};
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Contributor
{
friend ostream& operator << (ostream& output, Contributor& RHS);
friend istream& operator >> (istream& input, Contributor& RHS);
public:
Contributor();
Contributor(string Name, double Contribution, Gender MF, int IDKey);
Contributor(const Contributor ©);
Contributor& operator=(const Contributor& RHS);
bool operator== (const Contributor& RHS);
~Contributor() {cout << "In Contributor Destructor" << endl;}
private:
std::string Name;
double Contribution;
Gender MF;
int IDKey;
};
Then I tried to overload the extraction operator thus:
istream& operator >> (istream& input, Contributor& RHS)
{
cout << "\nEnter a new contributor's name: ";
std::getline (cin, RHS.Name);
cout << "Enter the amount of their contribution: ";
cin >> RHS.Contribution;
cout << "What is the gender of the contributor? ";
cin >> RHS.MF;
cout << "Assign an ID Key to the contributor: ";
cin >> RHS.IDKey;
return input;
}
But I keep getting this error: error C2679: binary '>>' : no operator
found which takes a right-hand operand of type 'Gender' (or there is
no acceptable conversion)
I've got gender defined in my constructors as well as the overloading
implementation. I don't understand why I'm getting this error. Can
someone help?
Many thanks.
#ifndef CONTRIBUTOR_H
#define CONTRIBUTOR_H
enum Gender {male=1, female, unk};
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Contributor
{
friend ostream& operator << (ostream& output, Contributor& RHS);
friend istream& operator >> (istream& input, Contributor& RHS);
public:
Contributor();
Contributor(string Name, double Contribution, Gender MF, int IDKey);
Contributor(const Contributor ©);
Contributor& operator=(const Contributor& RHS);
bool operator== (const Contributor& RHS);
~Contributor() {cout << "In Contributor Destructor" << endl;}
private:
std::string Name;
double Contribution;
Gender MF;
int IDKey;
};
Then I tried to overload the extraction operator thus:
istream& operator >> (istream& input, Contributor& RHS)
{
cout << "\nEnter a new contributor's name: ";
std::getline (cin, RHS.Name);
cout << "Enter the amount of their contribution: ";
cin >> RHS.Contribution;
cout << "What is the gender of the contributor? ";
cin >> RHS.MF;
cout << "Assign an ID Key to the contributor: ";
cin >> RHS.IDKey;
return input;
}
But I keep getting this error: error C2679: binary '>>' : no operator
found which takes a right-hand operand of type 'Gender' (or there is
no acceptable conversion)
I've got gender defined in my constructors as well as the overloading
implementation. I don't understand why I'm getting this error. Can
someone help?
Many thanks.