私はダミーのためにc++を見ていて、このコードを見つけました
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int nextStudentId = 1000; // first legal Student ID
class StudentId
{
public:
StudentId()
{
value = nextStudentId++;
cout << "Take next student id " << value << endl;
}
// int constructor allows user to assign id
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[])
{
// create a couple of students
Student s1("Chester");
Student s2("Trude");
// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
これが出力です
次の学生ID1000を取る
学生チェスターの構築
次の学生ID1001を取得します
学生の真実を構築する
何かキーを押すと続行します 。。。
値がそれに1を追加してからそれを出力する場合、最初の学生IDが1000である理由を理解するのに非常に苦労しています。
これは意味がありますか
StudentIdのコンストラクターで、2行のコードを取得nextStudentId
して1つ追加すると、出力されます。
出力は次のようなものではありません:
次の学生ID1001を取得します
学生チェスターの構築
次の学生ID1002を取得します
学生の真実を構築する
何かキーを押すと続行します 。。。
私が言おうとしていることをあなたが理解してくれることを願っています
ありがとう
ルーク