#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