简体   繁体   中英

Can Someone Explain Why My Getter Function Doesn't Call?

I'm writing some code to create a student class and a menu that allows the user to input and display information. Im running into some issues getting my GetName function to call. Here is my code:

#include <iostream>
using namespace std;


class Student {
  string FirstName, LastName, Birthday;
  int MNumber, Age;
  float GPA;
  public:
  void GetName(){
    cout << "Please enter your First Name." << endl;
    cin >> FirstName;
    cout << "Please enter your Last Name." << endl;
    cin >> LastName;
    cout << FirstName << ", " << LastName << endl;
  }
};

int main () {
 Student GetName;

  return 0;

}
} 

You're not calling the "Getname" method inside main program.

#include <iostream>
using namespace std;


class Student {
  string FirstName, LastName, Birthday;
  int MNumber, Age;
  float GPA;
  public:
  void GetName(){
    cout << "Please enter your First Name." << endl;
    cin >> FirstName;
    cout << "Please enter your Last Name." << endl;
    cin >> LastName;
    cout << FirstName << ", " << LastName << endl;
  }
};
int main () {
    Student getName;
    getName.GetName();
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM