🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.bbs.comp.program
1 messages
1 total messages Started by ���ܵ�Сʨ Sat, 18 Apr 1998 00:00
Visual C++ �еĶ��������
#1270
Author: ���ܵ�Сʨ
Date: Sat, 18 Apr 1998 00:00
163 lines
10070 bytes
  Visual C++�ж����ʱ��������ʱȡ��,������������,�dz���Ա
�ȽϹ��ĵ�����,���?�û�����ڴ��˷�,Ӱ��Ӧ�õ����С�����ͨ
��һ��������̽��һ��������⡣
    ����������
    �Ӷ��󱻴���������ȡ����һ�ڼ����dz�֮Ϊ���������ڡ�
ҪŪ�����������ʵ���Ͼ���ҪŪ������ʱ����������ʱ��ȡ��
���������⡣����Ĵ����ǽ�Ϊֱ�۵�,�������ʱ��ȡ��(�ͷ�����
ռ���ڴ���)�ƺ��Ƚϳ���һ�㡣����ʲôʱ�̡�������˳�򴴽�/ 
ȡ�����(����ijһ������Ʒ�Χ�ڰ�������)��ijЩC++ ����Ա
�������ܲ���ʮ�����������֪��:�κ�һ�������ڴ���/ȡ��ʱ����
��������Ӧ�Ĺ��� /�������� ��������ù��캯��(��������)��
������ʼ����ı����������ڴ�(�ͷ��ڴ漰����)����������ӡ��
Ϣ֮���"��ʾ"����, ���ǾͿ���ͨ����ʾ����Ϣ��֪ij�����Ǻ�ʱ
����������ʱ��ȡ��ġ�
    ��������һ�������ַ�ʽ:
    1.��ջ�ж������,��һ���ʽ����:
     ���� ������ (�����);
    ջ�ж�����ص�:������ִ�г���ջ��������������ʱ(���ڸ�
������������ֹʱ) ,���ǻ��Զ�����������Ӧ�������������ͷ�
���Ӧ������ռ���ڴ����������ƺ�����

    2.�ڶ����������(�����ɴ洢���з������),��һ���ʽ����:
    ����* ��ָ���� = new ���� (�����);
    ���ж�����ص�:һ�������ڶ��д���,����ִ�й���г��ʹ��
delete�Ȳ�������ȡ��ö���,����ö���һֱ�����ȥ��������d
eleteʹ�ø�ʽ����:
    delete ��ָ����;
    ִ�и������������ͷŸ�ָ����ָ������ռ�����ɴ洢����
�˶��������һ���Ѷ������������,delete������������������
��������Ҫ��������:�ͷŶ�Ӧ������ռ���ɴ洢�����ƺ�����;
����delete���������ñ�����Ϊ�ú����Զ���ɵ������������ͷ�
���ɴ洢��
    �������
    #include "iostream.h"
    #include "conio.h"
    class k{
      public:
      k()
      {
        cout << "enter k class " << endl;
      }
      ��k()
      {
        cout << "out of k class " << endl;
      }
    };//class k
    class kkk{
      public:
      kkk()
      {
        cout << "enter kkk class " << endl;
      }
      ��kkk()
      {
        cout << "out of kkk class " << endl;
      }
    };//class kkk
    class kk{
      public:
      kk()
      {
        cout << "enter kk class " << endl;
        kkk third;
      }
      ��kk()
      {
        cout << "out of kk class " << endl;
      }
      k first;
    };//class kk
    class xq:public kk,virtual public k,protected kkk{
    public:
    xq()
    {
      cout << "enter class xq" <<endl;
    }
    k first;
    ��xq()
    {
      cout << "come out class xq " << endl;
      cout << endl;
    }
    kk second;
    }; // class xq
    k* point = new k;
    kkk third;
    void main(void)
    {
      cout << "enter the main functoin !" << endl;
      xq ttt;
      getch();
    }
    ����ִ�н������:
    enter k class
    enter kkk class
    enter the main functoin !
    enter k class
    enter k class
    enter kk class
    enter kkk class
    out of kkk class
    enter kkk class
    enter k class
    enter k class
    enter kk class
    enter kkk class
    out of kkk class
    enter class xq
    come out class xq
    out of kk class
    out of k class
    out of k class
    out of kkk class
    out of kk class
    out of k class
    out of k class
    out of kkk class
    ͨ����������,�����ܽ����¹���:

    1.�����ڶ�����new  �Ȳ���������Ķ���,��̲����Զ��ͷ���
��ռ�����ɴ洢��,ֻ��ͨ�����Աʹ��delete�Ȳ��������ͷŸö�
����ռ���ɴ洢���䴴����˳��Ϊ:˭�ȱ�����,˭�ȱ�����;��ȡ
���˳��Ϊ:˭��ʹ�ò�����ȡ��,��˭�ȱ�ȡ���仰˵:�ڶ���
��������䴴����ȡ��˳��ֻ�����Ա�IJ���˳���йء��� ��ij��
���������Ӧ��������Χ��δ��ȡ��(ָ�ڶ��д����Ķ���),����
����û�����ʵ��Ĵ���,��ô������뿪�ö���������Χ���޷�
������з���,������ռ�����ɴ洢��δ��ȡ��,����ͻ���ɶ���
����˷ѡ��ʽ������ڲ�ʹ����Щ����ʱ,һ����Ҫ�����delete
�Ȳ�������ȡ�����ǡ�
    2.������ջ�ж���Ķ���,������ִ�г����ö����������ʱ��
���Զ�ȡ����ڴ���ͬһ������Ʒ�Χ�Ķ���,�䴴��˳��Ϊ:˭��
������˭�ȱ�����;��ȡ��˳���봴��˳��պ��෴(ջʽ������ص�
)�����ǿ�����"{"��"}"������������������ڡ��ɴ˿ɼ�,������
��������Ķ���,�䴴����ȡ��Ƚ������ջ�ж��������Щ,������
�粻������˵��,̸���Ķ����ָ��ջ�ж���Ķ���

    3.������е���ݳ�Ա�����(��Ƕ�������Ƕ��)����������
���캯������,��ô�䴴��˳��Ϊ:�ȴ������캯����Ķ���(��
��������˽�С����л򱣻�����,һ�ɰ��������г��ֵ�˳�����ȵ�
�󴴽�),Ȼ�󴴽��������,��󴴽����캯���еĶ���(�䴴��˳��
��ӹ���2��ԭ��)����ȡ��˳��Ϊ:�����ڹ��캯���д����Ķ���,��
���캯����ý���ʱ, ��̽��ᰴ�봴��ʱ�෴��˳����ȡ������;
�����ڹ��캯����Ķ���, ������ִ�г����������������Χʱ, 
��̽����봴��ʱ�෴��˳����ȡ�����ǡ���Ҫ�������ж����Ƕ��
�Ķ���ʱ,��̽������������������д���,����ȡ��ʱ���봴��
�෴��������еij�Ա�����ж���(����)�˶���,���ҽ����ó�Ա��
�����ʱ,��Щ�ڳ�Ա�����еĶ���Żᱻ����,������뿪�˺���
ʱ���Զ�ȡ����Щ����(�����ڶ�������Ķ���ֻ���ɳ���Ա������
ȡ��)��������е����������ж���(����)�˶���,��ֻ�и���������
������ʱ���Dzű�����, ������뿪����������ʱ��̻��Զ�ȡ����
�ǡ�

    4.�������������Ĵ���������Ĺ���:�ȴ�����Ļ���,�󴴽�
���? ���������˳��Ϊ:��˵�����Ⱥ�˳�򴴽�(�������к�����
����ʱ,��������ڷ����ഴ��)�� ��Ȼ,��������������Ƕ����,��
��������ʱ,Ӧ��ѭ����3)��
    5.����ȫ�̶���,�乹�캯���ڵ���main ����֮ǰ������,����
��������main����������֮����Ϊ�˳���̵� һ���ֶ����(��
���ڶ��������ȫ�̶����ȡ������ɳ���Ա�����)��

--
�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads