#include <iostream>
#include <cstring>
using namespace std;
struct Student {
int no;
char grade[14];
};
void set(struct Student* student);
void display(struct Student student);
int main() {
struct Student harry = {975, "ABC"};
set(&harry);
display(harry);
}
void set(struct Student* student){
struct Student jim = {306, "BBB"};
*student = jim; // this works
//*student.no = 306; // does not work
}
void display(struct Student student){
cout << "Grades for " << student.no;
cout << " : " << student.grade << endl;
}
我怎样才能改变结构只是一个成员的指针? * student.no = 306为什么不起作用?只是有点困惑。如何更改结构体指针的单个成员的值?
我强烈建议你看看如何用C++改变OOP。 – chris 2013-02-08 21:15:26