类和对象的使用
2016-03-19 19:24
197 查看
#include <iostream>
using namespace std;
class Student
{
public:
void print()
{
cout << name << "," << id << endl;
}
private:
char name[128];
int id;
};
int main()
{
Student stu;
stu.print();
return 0;
}
定义成员函数:
在public/private中定义函数 int getid()
在类外: int Student::getid()
{
}
对象的引用方法:
1.使用“."
Student stu;
stu.printf;
2.指针
Student*p=&stu;
p->getprint()
3.引用
Student &s=stu;
s.print();
using namespace std;
class Student
{
public:
void print()
{
cout << name << "," << id << endl;
}
private:
char name[128];
int id;
};
int main()
{
Student stu;
stu.print();
return 0;
}
定义成员函数:
在public/private中定义函数 int getid()
在类外: int Student::getid()
{
}
对象的引用方法:
1.使用“."
Student stu;
stu.printf;
2.指针
Student*p=&stu;
p->getprint()
3.引用
Student &s=stu;
s.print();
相关文章推荐
- ok6410串口裸机总结
- gradle
- 【代码】模板动态线性表&类型萃取
- Linux中安装Code:Blocks
- 构造函数中调用虚函数?
- 第四周项目4-程序分析(3)
- jQuery操作radio、checkbox、select总结
- 43. Multiply Strings | Java最短代码实现
- C++面试题10
- HDU 4323 Magic Number(DP)
- 操作系统 杂记
- Linux下RPM软件包的安装及卸载
- C++面试题9
- 02docker简单使用和配置(网络、存储和Hub)
- H - The equation——(SGU 106)
- 第三次作业 阅读程序有符号 64 位整数数据类型
- Visual Studio 开发平台的安装与单元测试
- SQL总结及注意点
- (3)ICE服务员起到的作用
- C++面试题8