クラスとポインタ

1327 ワード

構造関数の構築には、次の2つの方法があります.
range::range (float a ,float b,float c){width=a,length=b,hight=c;
 cout<

この方法を書くとき,関数内部の順序は関係ない.
2、
range::range(float a,float b,float c)
    {width=a,length=b,hight=c,cout<

eg:
class  A
{ public :   //        public
       A( ) { cout<

コンストラクション関数コンプライアンス:最初のコンストラクション、後のコンストラクション、前のコンストラクション***
オブジェクト配列を作成するには:
  • 各要素はオブジェクト
  • です.
  • 配列の複数のオブジェクトが何個あるかについて、複数のコンストラクタコードブロックを呼び出す:
  • class range
    {
        float width;
        float length;
        float hight;
        float area;
        int x;
    public:  
    
    range::range(float a,float b,float c)
        {width=a,length=b,hight=c,cout<x=a;}  
    float range::getarea(void)
        {return width*length*hight;}  
    }  
    int main()
    {
        range data[3]={range(2,3,4),range(5,6,7),range(22,2,2)};
        for(int i=0;i<3;i++)
            cout<

    実行結果:
    構造解析関数成功構造解析関数成功構造解析関数成功配列1の面積:24配列2の面積:210配列3の面積:88任意のキーを押して続行してください.***
    オブジェクトポインタと配列:
    class point
    {
        int x,y;
        static int count;
    public:
        void set_data(int a,int b){x=a,y=b;}
        void display(void)
        {
            cout<set_data(i,i+2);
            //a[i].set_data(i,i+2);
            p[i]->display();
            (*p)++;
        }
    system("pause");
    return 0;
    }