首页 > 试题广场 >

完成下列程序,使得该程序输出结果如下:

[填空题]

完成下列程序,使得该程序输出结果如下:

number of instance: 1

number of instance: 2

number of instance: 1

number of instance: 0

#include "iostream.h"

class Process

{

    static int instance;

    public:

        Process( )

        {

            1

        }

        ~Process( )

        {

             2

        }    

    static void print( )

    {

        cout << "number of instance: " << instance << endl;

    }

};

3

int main( )

{

    Process *p1, *p2;

    p1 = new Process;

    p1->print( );

    p2 = new Process;

    p2->print( );

    delete p1;

    Process::print( );

    delete p2;

    Process::print( );

    return 0;

}
1. instance++;
2. instance--;
3. int Process::instance = 0;
发表于 2020-12-21 20:41:51 回复(0)