源程式:
#include <iostream>
using namespace std;
class B
{
private:
int data;
public:
B()
{
cout << "構造函數B" << endl;
}
B(int a)
{
data = a;
cout << "帶1個參數的構造函數B" << endl;
}
B play(B b)
{
return b;
}
~B()
{
cout << "析構函數B" << endl;
}
};
int main()
{
B temp;
temp.play(5);
system("pause");
return 1;
}
運作結果: