cannot call member function without object

后端 未结 4 1652
遥遥无期
遥遥无期 2020-11-27 19:09

This program has the user input name/age pairs and then outputs them, using a class. Here is the code.

#include \"std_lib_facilitie         


        
4条回答
  •  难免孤独
    2020-11-27 19:21

    just add static keyword at the starting of the function return type.. and then you can access the member function of the class without object:) for ex:

    static void Name_pairs::read_names()
    {
       cout << "Enter name: ";
       cin >> name;
       names.push_back(name);
       cout << endl;
    }
    

提交回复
热议问题