Being as straightforward as i can: i was messing around with input codes, trying to get myself used with C++ and i came to realize that this code works fine so far:
It doesn't work anymore, debug saying that "userInput" was not specified in that scope. So, i don't ~really~ need to make anything in this class public or private for what i'm trying to accomplish, but it's really bugging me that i can't understand why it's coming off wrong when i try it...
Thank you all very much (:
To declare a class function private or public, the declaration goes OUTSIDE the function.
1 2 3 4 5 6 7 8 9 10 11
class QA{
private: // everything after this is private
std::string userQuestion()
{
std::string userInput;
std::cin >> userInput;
return userInput;
}
public: // everything after this is public
};
That's not how you use the public: thing. In your first code, your function is private by default, everything in a class is private by default. If you want to make it public, which Im sure you would want that -
1 2 3 4 5 6 7 8 9 10 11 12 13
class QA{
public: // this goes here
std::string userQuestion()
{
std::string userInput;
std::cin >> userInput;
return userInput;
}
private:
};