Original Post
i'm trying to pass a static enum variable to a static function in a class. it's not happening. why? and the source: here are the errors:
#ifndef PERSON_H
#define PERSON_H
enum Gender {MALE, FEMALE};
class Person {
public:
Person( );
void returnGender () const;
void lastGenderMade (Gender);
private:
static Gender makeGender ( );
Gender gender;
};
#endif
#include <iostream>
#include "Person.h"
using namespace std;
void Person::returnGender () const {
if (gender == MALE)
cout << "This person is MALE" << endl;
else
cout << "This person is FEMALE" << endl;
}
Person::Person () {
gender = makeGender();
}
Gender Person::makeGender () {
static int counter = 0;
static Gender sex = MALE;
if (counter == 0) {
lastGenderMade(sex); //line 25
}
else {
lastGenderMade(sex); //line 28
if (sex == MALE)
sex = FEMALE;
else
sex = MALE;
}
++counter;
return sex;
}
void Person::lastGenderMade (Gender created) {
if (created == MALE)
cout << "This person is MALE" << endl;
else
cout << "This person is FEMALE" << endl;
}
Person.cpp D:\Dev-Cpp5\Projects\Person.cpp In static member function `static Gender Person::makeGender()':
25 D:\Dev-Cpp5\Projects\Person.cpp cannot call member function `void Person::lastGenderMade(Gender)' without object
28 D:\Dev-Cpp5\Projects\Person.cpp cannot call member function `void Person::lastGenderMade(Gender)' without object