我试图弄清楚课程是如何运作的,但我遇到了一些麻烦
主文件
#include <stdio.h>
#include "Student.h"
#include <stdlib.h>
void main()
{
Student students;
students.Print();
system("pause");
}
学生.h
#pragma once
#include <string.h>
#include <iostream>
using namespace std;
class Student
{
public:
Student(void);
~Student(void);
void Print(void);
private:
int IDone;
int IDtwo;
string studentOne;
string studentTwo;
};
学生.cpp
#include "Student.h"
Student::Student(void)
{
studentOne = "John Doe";
studentTwo = "Jane Doe";
IDone = 227768;
IDtwo = 227769;
}
Student::~Student(void)
{
}
void Student::Print(void)
{
printf("Student name: %s\n", studentOne);
printf("Student ID: %d\n", IDone);
printf("Student name: %s\n", studentTwo);
printf("Student ID: %d\n", IDtwo);
}
当它运行时,我得到:
Student name: <null>
Student ID: 227768
Student name: <null>
Student ID: 227769
稍后我希望能够更改名称和 ID。此外,可以将这些成员放在一种数组中,这样我就可以通过 student[0] 和 student[1] 来打印它?