虚函数
摘要:/*虚函数*//***********************************************************************虚函数建立在继承情况下的虚函数:一个成员函数(不包括构造函数和静态成员函数)前面有virtual关键字虚函数好处: 可以用一致的(相同的)方法,在不同种情况,完成不一样的实现用同样的接口,完成不同的实现虚函数写法: 1.在基类和派生类中,有...
阅读全文
类的继承(2)
摘要:/*类的继承(2)*/#include"stdafx.h"#include <string.h>#include <iostream.h>class MyDate{public: MyDate() { cout << "成员构造" << endl; } ~MyDate() { cout << "成员构造" << endl; ...
阅读全文
类的继承(1)
摘要:/*类的继承(1)*/#include"stdafx.h"#include <iostream.h>#include <string.h>class A{public: A() { m_nData = 10; m_nPublic_A = 1; m_nProtected_A = 2; m_nPrivate_A = 3; } //成员函数是在类内 void FunA() { i...
阅读全文
类成员函数指针的语法
摘要:/*类成员函数指针的语法*//*****************************类.h文件************************************/#if !defined(AFX_ONLYOBJ_H__BABA5522_94E8_4F53_B979_27F3DD105320__INCLUDED_)#define AFX_ONLYOBJ_H__BABA5522_94E8_4...
阅读全文
类 -- 友元
摘要:#include"stdafx.h"#include <iostream.h>//向前声明class A;class B{public: int GetAData( A& obj );};class A{public: int GetData() const { return m_i; } A():m_i(10) { }; //friend关键字函数修饰符 //此函数和类A有友...
阅读全文
静态成员数据与函数
摘要:#include"stdafx.h"#include <iostream.h>#include <string.h>//设计一个学生类,可以统计学生的总人数void GetName(){ cout << "gobal fun" << endl;}class student{public: char m_szName[32];public: stati...
阅读全文
new delete
摘要:/*new delete*/#include"stdafx.h"#include <stdlib.h>#include <iostream.h>#include <string.h>struct student{ student() { cout << "student::student()" << endl; } student( ch...
阅读全文
类构造函数(4)
摘要:/*类构造函数(4)*/#include"stdafx.h"#include <string.h>#include <iostream.h>class Date{public: //表达式表构造 Date( int nYear = 1980 , int nMonth = 1, int nDay = 1 ) :m_nYear(nYear),m_nMonth(nMonth),m...
阅读全文
类的构造函数(3)
摘要:/*类的构造函数(3)*/ /*******************类文件***********************/ #include"stdafx.h"#include"A.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction/////////...
阅读全文
类的构造函数(2)
摘要:/*类的构造函数(2)*/#include"stdafx.h"#include <iostream.h>class Color{public: Color() { cout << this << " color 无参构造" << endl; } ~Color() { cout << this << " color 析构" &l...
阅读全文
类的构造函数(1)
摘要:/*类的构造函数(1)*/#include"stdafx.h"#include <iostream.h>class Time{private: //私有段 int m_nHour; int m_nMin; int m_nSecond;public: //公有段 //构造函数无返回值,名称是类名 //进入到构造对象已经存在,无法销毁 Time() { init(); cout <...
阅读全文
再来看看this指针
摘要:/*再来看看this指针*//************************************************************************1.通过写程序证明,C++中的成员变量是独立的,成员方法是共享的。************************************************************************/#includ...
阅读全文
讲讲this指针
摘要:/*讲讲this指针*///同样声明一个类class CMyPoint{private: //私数据成员 int m_nx; int m_ny; public: //公有成员函数声明+实现, 如果在类内中定义成员函数,它是内联函数 void setpoint(int nx,int ny) { //在成员函数中,可以使用类中定义的数据成员 /**************************...
阅读全文
开始学习 类
摘要:/*开始学习类 */class person //class关键字声明一个类{private: //声明下面的成员为私有,就是只有类内部的成员才能使用,类外部就使用不了 int sex; //一个非常简单的私有数据成员 public: //声明下面的成员为公有,在类外部可以直接调用,下面的函数可以直接访问上面的私有成员 int height; //非常简单的公有数据,可以在类外部直接使用 int ...
阅读全文
const 修饰符的几种用法
摘要:const 修饰符的几种用法: 这玩意地球人都知道,不管什么东东被他修饰后就表示为常量,意思是不可修改.也可以理解为只读//最普通的用法,这个nTemp就是常量,下面的代码中不能再修改nTemp的值//否则编译器就会报错的//必须初始化constint nTemp = 10;//这样就错了constint nTemp;//但声明为外部的一个常量就可以externconstint nTemp;//这...
阅读全文