In main.cpp, you have these two lines before the main function:
Code:
std::string input;
std::string*pInput =&input;
Get rid of them as they should be in the main function instead, and in fact you do have the duplicate code in the main function.
In main, you do this:
The problem is that Mood doesn't have a default constructor because you declared another constructor without declaring the default constructor. You probably do want the default constructor, so let's leave this for now.
Next, this code again, but in main:
Code:
std::string input;
std::string*pInput =&input;
There is absolutely no need for pInput. What you should do is this:
Code:
std::string input;
std::cout << "Enter mood: ";
std::cin >> input;
mood1.setMood(input);
Now, you mentioned an error with setMood, but as far as I can tell, the error message does not correspond to your code, i.e., your code is correct. Perhaps you confused yourself by posting an error message from an earlier version of your code.
Now, in mood.h I would remove the protected label from the class definition since there are no members with protected access.
Going back to the constructor:
Code:
Mood(std::string*pInput);
As far as I can tell, you don't need this. You just want a default constructor that does what is default. Therefore, get rid of this. Likewise, get rid of the definition of this constructor in mood.cpp
If you prefer, you can explicitly declare the defaulted default constructor, so that even if you add other constructors later, it will continue to exist:
Next, this:
Code:
void setMood(std::string x);
should be:
Code:
void setMood(const std::string& x);
since you don't want a copy of the source string until you actually copy it into the mood member variable. Remember to make the corresponding change in mood.cpp
(Well, it is okay to make a copy at that point since you do need a copy either way, but then for efficiency you would want to invoke the move assignment operator for the mood member variable instead... not much point bothering with that when you can just defer the copy and do copy assignment later.)
Finally, this:
Code:
std::string getMood();
should be:
Code:
std::string getMood() const;
since you want to be able to call getMood on a Mood object that is in a const context. Again, remember to make the corresponding change in mood.cpp