We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The default initialization of an int is zero, so they are incrementing the static count prior to the assignment. This will yield 1 for the first object created. If you wanted to explicitly initialize a static data member, it would be defined outside of the class, e.g.:
int Student::student_id = 0;
Normally, the static members would be declared in the header file, and initialized similar to the above at the top of the implementation file.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Virtual Functions
You are viewing a single comment's thread. Return to all comments →
The default initialization of an int is zero, so they are incrementing the static count prior to the assignment. This will yield 1 for the first object created. If you wanted to explicitly initialize a static data member, it would be defined outside of the class, e.g.:
int Student::student_id = 0;
Normally, the static members would be declared in the header file, and initialized similar to the above at the top of the implementation file.