64,646
社区成员
发帖
与我相关
我的任务
分享
struct Student
{
char num[30];
int score = 0; //这里就报错
int n ;
int question[11];
};
class Student
{
char num[30];
int score;
int n ;
int question[11];
const int student_id; // 学号
public:
Student(int id) : score(0), student_id(id) { // 使用成员初始化列表。
score = 0; // 这种方法也可以,不过对于常量就没办法了。
//student_id = id; // 编译错误
}
};
#include <utility>
class C2 {
double fsafsa;
float fdas;
};
class C1 {
private:
int a, b, c, d;
bool e[100];
Complex* pNext;
C2 subclass;
};
int main() {
C1 c;
C1 b;
c = b; // 虽然这些数据成员都是私有的,但此处编译并没有问题。
std::swap(c, b); // 使用了STL中的函数,实现了交换数据。
// 也可以不用STL中的函数:
{
C1 temp;
temp = c;
c = b;
b = temp;
} // 这看起来相当啰嗦
}
struct stStudent // 声明结构体
{
char num[30];
int score;
int n ;
int question[11];
};
struct stStudent Student={"", 0, 0, {0}}; // 定义结构体变量
memset(&S_student,0,sizeof(Student));
struct Student
{
char num[30];
int score ;
int n ;
int question[11];
}S_student;
memset(&S_student,0,sizeof(S_student));