The “cannot call member function without object” error is a common C++ error that occurs while working with classes and objects. The error is thrown when someone tries to access the functions of a class without instantiating it. Your question was, how to get rid of this? simple, just create an object of that class and call the object from your main function before using its methods. Lrt’s create an object of your public class and use its method inside the man function.
using namespace std;
string name = "Roy";
int age = 27;
cout << "Student Name: " << name << endl;
cout << "Student Age: " << age << endl;
Student myobj; // Creating an object
myobj.printValue(); // Calling method
Now you are all set to go and the program should give back your expected output:
Student Name: Roy
Student Age: 27
Keep asking without any hesitation.