Hello I didn't use C++ for years now, so I'm kinda rusty and can't figure this out!
I have this code | person.h
#ifndef PERSON_H
#define PERSON_H
#include<string>
class Person {
private:
std::string fName, lName;
int age;
enum professionEnum {
Barber,
Developer,
Marketer
} profession;
public:
Person();
Person(std::string fName, std::string lName, int profession);
void setFName(std::string fName);
void print();
};
#endif
a simple person class.
What I want to do is for my constructor Person() to take an int, example :
Person me = Person("me", "meow", 0); // This should assign "me" to Barber, enum index is 0.
Here is what I tried so far (all errors):
this->profession = professionEnum::profession;
this->profession = 0;
this->profession = professionEnum(profession);
Here is the full person.cpp code
#include "person.h"
#include <iostream>
Person::Person() {
this->age = 18;
this->fName = "Default";
this->lName = "Default";
}
Person::Person(std::string fName, std::string lName, int profession) {
this->fName = fName;
this->lName = lName;
this->profession = professionEnum::profession;
this->profession = 0;
this->profession = professionEnum(profession);
}
void Person::print() {
std::cout << "Age : " << this->age << ", FName : " << this->fName << ", LName : " << this->lName << std::endl;
}
Thanks for your help
PS: If you spot any bad practices / bad code, please tell me.