My ide is showing linter error in the following code. It is highliting yellow in the int main() student s; part
using namespace std;
class student {
public:
int age,DOB;
char name[32];
void getData() {
cin >> age >> DOB >> name;
}
void display() {
cout << name << ends << age << ends << DOB ;
}
};
int main() {
student s;
s.getData();
s.display();
}
and the following code which is same but on adding curlys after student s in the int main student part solves the problem
using namespace std;
class student {
public:
int age,DOB;
char name[32];
void getData() {
cin >> age >> DOB >> name;
}
void display() {
cout << name << ends << age << ends << DOB ;
}
};
int main() {
student s{};
s.getData();
s.display();
}
Your IDE most likely points out that the member variables of s
are not initialized.
Using {}
syntax ensures that it is initialized.
You can read more about typed of initialization in C++ here.