Question: C++ Can someone explain why I'm getting the following error? Here is my code #include #include using namespace std; class Student { private: int age;
C++
Can someone explain why I'm getting the following error?
Here is my code
#include
class Student { private: int age; string name;
public: Student(): age(0), name("") {} Student(string name, int age):name(name), age(age) {} int getAge() { return age; } string getName() { return name; } void setAge(int age) { this->age = age; } void setName(string name) { this->name = name; }
};
int main() { Student me; Student joe; me.setAge(25); me.setName("Emmanuel"); joe.setAge(21); joe.setName("Joe"); Student* stud1 = &me; Student* stud2 = &joe; cout name age name age
this is the error

emmang:~/workspace $ g++ pointer.cpp pointer.cpp: In function int main)': pointer.cpp:9:12: error: std: : string Student: :name' is private string name; pointer.cpp:39:32: error: within this context cout age name age
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
