1.静态成员函数中不能使用this指针;静态成员函数并不具体作用于某个对象;
2.普通成员函数每个对象一个,静态成员函数所有对象共享一个;eg.A::f();//等于// r1.f();
3.静态成员函数不需要通过对象就能访问;
4.静态成员变量和静态成员函数本质上是全局变量和全局函数;
5.必须在定义类的文件中对静态成员变量进行声明或初始化,否则编译能通过,链接不能通过;
6.静态成员函数中,不能访问非静态成员变量和非静态成员函数,因为不知道是哪个对象的;
7.有成员对象的类叫封闭类;封闭类应该通过(封闭类的构造函数的初始化列表)来进行初始化;
8.封闭类执行构造函数的顺序:成员函数-->封闭类;(engine-->car)封闭类执行析构函数的顺序:封闭类-->成员函数;(car-->engine)
9.友元函数:一个类的友元函数中,该类的对象可以访问该类的私有变量;//一般对象不能访问该类的私有变量,只能通过成员函数访问;
10.友元类:若A是B的友元类,那么A的成员函数可以访问B的私有变量;
11.常量成员函数:const A a;//常量对象只能构造函数,析构函数,以及有const说明的方法;
a.f();//error
void f() const{//常量成员函数//const A a;-->对象 void f() const{}-->函数
//内部不能改变属性的值,也不能调用非常量成员函数;
}
12.mutable int a;
可以在const 成员函数中修改a;
13.strtok()的用法
(1).char str[]="- this is, a girl, ok.";
char *p=strtok( str ," -.," );
while(p!=NULL){
cout<<p<<endl;
p=strtok(NULL," -.,");
}
(2). void input(){
char buf[210];
cin.getline(buf,200);
char * p=strtok(buf,",");
strcpy(name,p);
p=strtok(NULL,",");
age=atoi(p);
p=strtok(NULL,",");
id=atoi(p);
for(int i=0;i<MUN;i++){
p=strtok(NULL,",");
score[i]=atoi(p);
}
}
001:(Program Completion) Student Information Processing
#include<cstdio>
#include<iostream>//cin cout
#include<string.h>//<string>ÊDz»¶ÔµÄ£¬Ó¦¸Ã¼Ó.h
#include<cstdlib>
#include<cmath>
#include<vector>//¶þάÊý×é
#include<algorithm>//
#include<set>//¼¯ºÏ
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;
const int maxn=1010;
const int inf=0x3fffffff;
const double minx=1e-8;
class student{
private:
static const int MUN=4;
int age,id;
char name[20];
int score[MUN];
public:
int calculate(){
int sum=0;
for(int i=0;i<MUN;i++){
sum+=score[i];
}
return sum/MUN;
}
void input(){
char buf[210];
cin.getline(buf,200);
char *p=strtok(buf,",");
strcpy(name,p);
p=strtok(NULL,",");
age=atoi(p);
p=strtok(NULL,",");
id=atoi(p);
for(int i=0;i<MUN;i++){
p=strtok(NULL,",");
score[i]=atoi(p);
}
}
void output(){
cout<<name<<",";
cout<<age<<","<<id<<","<<calculate()<<endl;;
}
};
int main(){
student stu;
stu.input();
stu.calculate();
stu.output();
system("pause");
return 0;
}
2466

被折叠的 条评论
为什么被折叠?



