C++数组和类
2013-11-03 11:32
211 查看
C++中类的引用产生了新的数组类型,对象数组和对象指针数组下面已经定义的Point类定义的一般类的对象、数组对象、对象指针数组的实例。
Point p1,p2[10];
Point *p3[5];
其中p1是一个普通对象、p2是一个对象数组,它有10个元素每个元素都是一个Point类的对象,p3[5]是一个对象指针数组。
访问对象的公有有成员函数的不同方式的例子:
Point p1,p2[10];
Point *p3[5];
其中p1是一个普通对象、p2是一个对象数组,它有10个元素每个元素都是一个Point类的对象,p3[5]是一个对象指针数组。
访问对象的公有有成员函数的不同方式的例子:
#include <iostream> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; class Point{ private: int X; int Y; public: Point(int xx=0,int yy=0){ X=xx; Y=yy; } int GetX(){ return X; } int getY(){ return Y; } }; int main(int argc, char** argv) { Point A(4,5); Point *p1 = &A; int(Point:: *p_GetX)() = &Point::GetX; cout<<(A.*p_GetX)()<<endl; cout<<(p1->GetX())<<endl; return 0; }
相关文章推荐
- C++数组应用之特殊矩阵的压缩存储
- c++数组引用作为函数参数
- c++数组的解剖学 (转)
- C++数组学习杂记
- C++数组原地转置代码
- C++数组与指针
- 把《c++ primer》读薄(4-1 c和c++数组)
- Java数组与c++数组的区别
- C++数组与指针详解
- C++数组的二分法查找
- C++数组与指针讲解
- C++数组到底可以开多大?
- C++数组:数组元素、存储引用以及作为函数参数
- C++数组越界了还是可以输出越界的字符
- C++数组应用之特殊矩阵的压缩存储
- c++数组引用作为函数参数
- C++数组越界不检查
- C++数组学习杂记
- c++数组引用一二
- C++数组(一维、二维、三维)的动态分配new、初始化memset和释放delete