I am looking at C ++ for mannequins and found this code
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int nextStudentId = 1000;
class StudentId
{
public:
StudentId()
{
value = nextStudentId++;
cout << "Take next student id " << value << endl;
}
StudentId(int id)
{
value = id;
cout << "Assign student id " << value << endl;
}
protected:
int value;
};
class Student
{
public:
Student(const char* pName)
{
cout << "constructing Student " << pName << endl;
name = pName;
semesterHours = 0;
gpa = 0.0;
}
protected:
string name;
int semesterHours;
float gpa;
StudentId id;
};
int main(int argcs, char* pArgs[])
{
Student s1("Chester");
Student s2("Trude");
system("PAUSE");
return 0;
}
this is a conclusion
Take the next student id 1000
student building chester
Take the following student ID 1001
building student work
Press any key to continue.,.
I find it very difficult to understand why the first student ID is 1000 if the value adds it to it and then prints it
it makes sense
right in the constructor for studentId take two lines of code nextStudentIdand add one to it, then print
Something like this will not be output:
Take the following student ID 1001
student building chester
Take the next student id 1002
building student work
Press any key to continue.,.
hope you get what I'm trying to say
thank
Luke
user451498
source
share