复习题1

#include<iostream>
 
using namespace std;
 
class Cup
{
private:
    int volume;
public:
    Cup(int v=0):volume(v)
    {
        cout<<"A cup of "<<volume<<" ml is created."<<endl;
    }
    Cup(const Cup& c):volume(c.volume)
    {
        cout<<"A cup of "<<volume<<" ml is copied."<<endl;
    }
    ~Cup()
    {
        cout<<"A cup of "<<volume<<" ml is erased."<<endl;
    }
    void setVolume(int v)
    {
        volume=v;
    }
};
int main()
{
    Cup c1;
    int i, j;
    cin>>i>>j;
    Cup c2(i), c3(c2);
    c3.setVolume(j);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/pxxfxxxx/p/11137497.html