I'm trying to create a contributor class with one enumerated type. I took the member functions from the header and put them in a cpp, but I get an error for the enumerated type when I try to compile. Is it because I haven't written a code body for that member function yet? Files below, header first...oh, I'd also like to ask if everything looks okay so far.

#pragma once
#include <string>
#include <iostream>
using namespace std;

enum gender {male,female,none};

class Contributor
{
	public:
		Contributor();
		Contributor (string Name, double Donation =0.0, gender sex=none, int IDKey=0);
		Contributor (const Contributor& InContributor);
		~Contributor();
		friend ostream& operator << (ostream& out, Contributor& InContributor);
		friend istream& operator >> (istream& in, Contributor& InContributor);
		Contributor& operator = (const Contributor& rtside);
		bool operator <  (const Contributor& rtside);
		bool operator >  (const Contributor& rtside);
		bool operator == (const Contributor& rtside);
		bool operator != (const Contributor& rtside);

	private:
		string Name;
		double Donation;
		int IDKey;
		enum gender;
};

Here's the beginning cpp, no function defs yet

#include "Contributor class.h"


Contributor::Contributor()
{
}

Contributor::Contributor (string Name, double Donation, gender sex, int IDKey)
{
}
		
Contributor::Contributor (const Contributor& InContributor)
{
}

Contributor::~Contributor()
{
}

ostream& operator << (ostream& out, Contributor& InContributor)
{
}

istream& operator >> (istream& in, Contributor& InContributor)
{
}

Contributor& Contributor::operator = (const Contributor& rtside)
{
}
		
bool Contributor::operator <  (const Contributor& rtside)
{
}

bool Contributor::operator >  (const Contributor& rtside)
{
}

bool Contributor::operator == (const Contributor& rtside)
{
}

bool Contributor::operator != (const Contributor& rtside)
{
}

Err, what exactly is the error you get? From what line?

error C2511: 'Contributor::Contributor(std::string,double,Contributor::gender,int)' : overloaded member function not found in 'Contributor'
see declaration of 'Contributor'

error C2511: 'Contributor::Contributor(std::string,double,Contributor::gender,int)' : overloaded member function not found in 'Contributor'
see declaration of 'Contributor'

Can't say I'm 100% sure - but after looking at it a bit I'm pretty sure:

You have two enumerations. The first is gender, which is declared and defined in global scope. The second is Contributor::gender, which is declared as a private member of the Contributor class. When you declare the constructor we're dealing with in the .h file, one of it's types is gender, and since we're in the scope of Contributor, it is assumed that gender refers to Contributor::gender. However, when you define the constructor in the .cpp file, you say gender once again, only this time, you're referring to the global gender enumeration (since we're in global scope), and so the compiler complains that you're defining an overloaded method with different parameter types than any of the ones in the class declaration.

I'm assuming you only wanted one enumeration. Take the line that first declares gender (outside of the class), and move it to the top of the .cpp file, and change it from enum gender ... to enum Contributor::gender...

thanks for the attempt cg, but that wasn't it. I only compounded my problem with that

error C2511: 'Contributor::Contributor(std::string,double,Contributor::gender,int)' : overloaded member function not found in 'Contributor'
see declaration of 'Contributor'

In the class declaration, you probably meant to have a member variable like gender Sex; instead of enum gender;

that seems to have done it, now I have the errors I expected to have for empty functions that should be returning values

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.