Someone could tell me how I should define a private function in c ++. I have this class definition.
#ifndef AUTHOR_H_
#define AUTHOR_H_
#include <string>
#include <iostream>
using namespace std;
class Author {
private:
string name;
string email;
char gender;
public:
Author();
Author(string name, string email, char gender);
Author(const Author &rAuthor);
Author & operator=(const Author &rAuthor);
~Author();
string getName() const;
string getEmail() const;
char getGender() const;
void setEmail(string email);
void setEmail_2(string email);
void print() const;
bool checkGender(char gender) const;
};
#endif /* AUTHOR_H_ */
And I would like the checkGender
method to be private, but if I put it in the private part the Author.h
file, when defining the functions it does not appear to me as belonging to the class Author
. I want to define it as private because it will be used by the constructor of my class, but I do not want to make it visible.
Author.cpp File:
#include "Author.h"
Author::Author(){}
Author::Author(string name,string email, char gender){
this->name=name;
Author::setEmail_2(email);
if(Author::checkGender(gender))
this->gender=gender;
else
this->gender='';
}
bool Author::checkGender(char gender) const{
if(gender == 'm' || gender == 'f' || gender=='u'){
return true;
}else{
return false;
}
}
I think this is all the info, anything you tell me. Thanks.
If I change it to the private zone of the class you understand, var does not appear in the list of available methods, should it not appear in the methods of the class?
class Author {
private:
string name;
string email;
char gender;
bool checkGender(char gender) const;
public:
Author();
Author(string name, string email, char gender);
Author(const Author &rAuthor);
Author & operator=(const Author &rAuthor);
~Author();
string getName() const;
string getEmail() const;
char getGender() const;
void setEmail(string email);
void setEmail_2(string email);
void print() const;
//bool checkGender(char gender) const;
};