Avatar ·

Error "request for member '...' in '...' which is of non-class type" in C++

Hello everyone! I just started learning C++ and encountered an error I can't understand. I'm writing a simple program to work with a "Student" class. Here's the code:\n\n```cpp\n#include \n#include \nusing namespace std;\n\nclass Student {\npublic:\n string name;\n int age;\n \n void printInfo() {\n cout << "Name: " << name << ", Age: " << age << endl;\n }\n};\n\nint main() {\n Student* ptr;\n ptr = new Student();\n \n // Trying to fill data\n ptr.name = "Ivan";\n ptr.age = 20;\n \n ptr.printInfo();\n \n delete ptr;\n return 0;\n}\n```\n\nThe compiler gives an error: "error: request for member 'name' in 'ptr', which is of non-class type 'Student*'". I understand that ptr is a pointer, but I don't understand how to correctly access the fields.