vc++第2章 C++面向对象程序设计
2.1.4 对象成员初始化[例Ex_InitMultObject] 对象成员的初始化 #include <iostream.h> class CPoint { public: CPoint(int x, int y) { nPosX = x; nPosY = y; } void ShowPos() { cout<<"当前位置:x = "<<nPosX<<", y = "<<nPosY<<endl; private: int nPosX, nPosY; }; class CSize { public: CSize(int l, int w) { nLength = l; nWidth = w; } void ShowSize() { cout<<"当前大小:l = "<<nLength<<", w = "<<nWidth<<endl; } private: int nLength, nWidth; };
}