Error C2558

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Locked
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Error C2558

Post by Beowulf »

bit big...
contributor.h wrote:#ifndef CONTRIBUTOR_H //Preprocessor directives to prevent duplicate
#define CONTRIBUTOR_H // declarations. Use the file name of the identifier
//substituting an _ underscore for the period
//====================================================================
// CONSTANT DEFINITIONS

// formatting constants:
const int nameWidth = 30;

//******************************************************************************
// STANDARD AND USER DEFINED INCLUDES
#include <string>
#include <iostream>

using namespace std;
//******************************************************************************
// USER DEFINED DATA TYPES
class Contributor{
//friend functions
friend ostream & operator<<(ostream &out, Contributor RHS);
friend istream & operator>>(istream &in, Contributor &RHS);

public:
enum Gender{male, female, none};

//member functions
Contributor(string inName = string("A. Nonymous"), double inCont = 0.0,
Gender inSex = none, int inIDKey = 0);
Contributor(Contributor &inCont);
~Contributor();
Contributor &operator=(Contributor &RHS);
bool operator<(Contributor &RHS);
bool operator>(Contributor &RHS);
bool operator==(Contributor &RHS);
bool operator!=(Contributor &RHS);
string GetName() {return Name;}
double GetContribution() {return Contribution;}
Gender GetSex() {return Sex;}
int GetIDKey() {return IDKey;}
void SetName(string inName);
void SetContribution(double inCont);
void SetSex(Gender inSex);
void SetIDKey(int inIDKey);

static bool CompareByAlpha;
private:
string Name;
double Contribution;
Gender Sex;
int IDKey;
};
//******************************************************************************
// END OF CONDITIONAL BLOCK
#endif
//pop the stacks onto the final list
list<Contributor> Seating;

Seating.push_front(Contributor(string("Guest of Honor")));
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
Arrow
Jedi Council Member
Posts: 2283
Joined: 2003-01-12 09:14pm

Post by Arrow »

MSDN for error C2558 wrote: 'identifier' : no copy constructor available or copy constructor is declared 'explicit'

A copy constructor initializes an object from another object of the same type. (It makes a copy of the object.) The compiler generates a default copy constructor if you do not define any constructors.

Possible cause

Trying to copy a class whose copy constructor is private. In most cases, a class with a private copy constructor should not be copied. A common programming technique declares a private copy constructor to prevent the direct use of a class. The class may be useless by itself or require another class in order to work properly.
Trying to copy a class whose copy constructor is explicit. Declaring a copy constructor with explicit prevents passing/returning objects of a class to/from functions.
Possible solution

If you determine that it is safe to use a class with a private copy constructor, derive a new class from the class with a private constructor and make a public or protected copy constructor available in the new class. Use the derived class in place of the original.
For more information, see Compiler Errors when Implementing a CObject-Derived Class.
Have you tried declaring your private members as protected? Its been a long time since I've messed with copy constructors.
Artillery. Its what's for dinner.
User avatar
Akaramu Shinja
Little Stalker Boy
Posts: 260
Joined: 2005-07-26 05:35pm
Location: UK

Post by Akaramu Shinja »

You're not defining your copy constructors right. Try this.

Code: Select all

Contributor(const Contributor &inCont);
Contributor &operator=(const Contributor &RHS);
They need to be const.
アカラム

Image

I melt two faces in the morning. I melt two faces at night. I melt two faces in the afternoon, it makes me feel alright. I melt two faces in time of peace, and two in time of war. I melt two faces before I melt two faces, and then I melt two more. - Ballad of a PK
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Akaramu Shinja wrote:You're not defining your copy constructors right. Try this.

Code: Select all

Contributor(const Contributor &inCont);
Contributor &operator=(const Contributor &RHS);
They need to be const.
Ah... thank you. Fixed the error
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
Locked