C++基础2-类
来源:互联网 发布:linux 驱动编写 编辑:程序博客网 时间:2024/05/22 12:58
11 类的概念
#include "iostream.h"
using namespace std;
int score=0;
class test
{
public:
int name;
int score;
private:
int age;
int gender;
public:
void GetScore();
}
void test::GetScore()
{
::score=111;//全局变量赋值
score=11;//类变量赋值
}
void main()
{
test a;
test b;
a.GetScore;
cout<<"score"<<endl;
cout<<"a.score"<<endl;
}
注:
1.类里面不仅可以定义变量,还可以声明函数,称为类的成员函数
2.成员函数需要在类外,利用域区分符::定义
3.变量名前加域区分符,给全局变量赋值
4.public能被任何访问;protected仅能被类的成员函数、友元以及子类的成员函数和友元访问;private仅能被类的成员函数和友元访问。
0 0
- Objective-C类 基础
- c++:角色类,基础
- c基础(2)
- c基础2
- c语言基础 2
- C++SDL---基础2
- C基础 2
- c语言基础 (2)
- C基础2
- c语言基础2
- C语言基础2
- 2、C语言基础
- Linux C基础2
- C 基础练习2
- 基础c语言程序设计2
- C语言程序设计(基础2)
- C语言基础-2
- C语言基础2
- Linux下安装与配置MySQL
- HD 5428 The Factor
- 使用mantis测试缺陷步骤
- 09-04、05 ViewPager
- Fragment
- C++基础2-类
- mybatis实现的增删改查例子
- 第一次蹦极
- backtrack环境的基本配置之网络配置基本命令
- 38Count and Say
- Thread + Handle 解决子线程更新UI
- 是时候做点什么了
- WinCE6.0BSP移植(一)
- recyclerview 实现正方形网格效果