I'm new to C++ and this is the code where my pointer becomes null, what am I doing wrong?
Main Function.
// in main() function
switch (UserView::RequestMainMenuOption()) {
case 1:
{
struct user_info *user; // the pointer in question.
if (UserController::Login(user) && user) { // shows null here
std::cout << user->username << std::endl; // this line does not execute.
Controller.
bool UserController::Login(struct user_info *user)
{
//...
// std::cin username / password and validate in the user model.
if (User::ValidateCredentials(username, password, user)) {...}
}
Model.
int User::ValidateCredentials(std::string username, std::string password, struct user_info *user)
{
// UserList is a vector of struct user_info that contains std::string username, password;
std::vector<user_info> UserList = User::GetUserList();
// index is searched for here based on credentials...
// address of the element in the user list is assigned to user.
user = &UserList.at(index);
// address is successfully assigned (tested)
// but when returning back to the first function call in the main() function, user is NULL.