c++ class 初体验
来源:互联网 发布:e元素战隼z77宏编程 编辑:程序博客网 时间:2024/04/29 11:53
Visual Studio 2012
1. demo.cpp:------------------------------------#include <iostream>#include <stdlib.h>#include <string>#include "Student.h"using namespace std;/*****************************//* class类的使用,初始化列表的使用*//*****************************/int main(){ Student stu; /*cout<<stu.getName()<< " " <<stu.getScore()<<" "<<stu.getMax()<<endl; stu.study();*/ Student stu1(stu); return 0;}
2. Student.h:-----------------------------------#include <iostream>#include <string>using namespace std;class Student{public: Student(string name = "jim", int score = 12, int m =100); Student(const Student&stu); //拷贝构造函数 对象的复制 ~Student();//析构函数 释放资源 void setName(string _name); string getName(); void setGender(string _gender); string getGender(); void study(); int getScore(); int getMax();private: string m_strName; string m_strGender; int m_iSocre; const int m_iMax;//初始化列表};
3. Student.cpp:------------------------------------#include <iostream>#include <string>#include "Student.h"using namespace std;Student::Student(string name, int score, int m):m_strName(name),m_iSocre(score),m_iMax(m){ cout<<"Student(string name, int score)"<<endl; //m_iMax = 180;}Student::Student(const Student &stu):m_iMax(1){ cout<<"Student(const Student &stu)"<<endl;}Student::~Student(){ cout<<"~Student()"<<endl;}void Student::setName(string _name){ m_strName = _name;}string Student::getName(){ return m_strName;}void Student::setGender(string _gender){ m_strGender = _gender;}string Student::getGender(){ return m_strGender;}void Student::study(){ cout<<"studing..."<<endl;}int Student::getScore(){ return m_iSocre;}int Student::getMax(){ return m_iMax;}
0 0
- c++ class 初体验
- C#Builder初体验
- C语言初体验
- C#--数据库初体验
- C语言初体验
- Object-C初体验
- c-lodop初体验
- C的初体验
- sequoia(c-jdbc)初体验
- Objective-C Category初体验
- Objective-C Category初体验
- Objective-C Category初体验
- C语言程序初体验
- C.Class
- [C++]Class
- Objective-C 中Categories 初体验
- Objective-C Category类别 初体验
- Objective-C 面向对象初体验
- Listview如何提高其效率
- 在编写Spring框架的配置文件时,标签无提示符的解决办法
- Cairo开发环境安装与在VC++2012中简单实现
- 微服务产品级敏捷: 重新定义产品的集成测试
- Android中的线程池
- c++ class 初体验
- 161016回顾与复习
- XAML控件(control)
- 银行卡号提取识别技术
- 面向对象总结
- Listview如何定位到指定位置
- java虚拟机与反射机制
- 抛出异常throw和throws
- 在线选择题的答题及提交方式