954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Class trouble

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)
{
}
henpecked1
Posting Whiz in Training
245 posts since Dec 2007
Reputation Points: 10
Solved Threads: 2
 

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

CoolGamer48
Posting Pro in Training
401 posts since Jan 2008
Reputation Points: 77
Solved Threads: 40
 

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

henpecked1
Posting Whiz in Training
245 posts since Dec 2007
Reputation Points: 10
Solved Threads: 2
 
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...

CoolGamer48
Posting Pro in Training
401 posts since Jan 2008
Reputation Points: 77
Solved Threads: 40
 

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

henpecked1
Posting Whiz in Training
245 posts since Dec 2007
Reputation Points: 10
Solved Threads: 2
 
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 havea member variable like gender Sex; instead of enum gender;

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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

henpecked1
Posting Whiz in Training
245 posts since Dec 2007
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You