天天看點

轉換構造函數

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Swap {
private:
	int a, b;
public:
	Swap(int n,int m):a(n),b(m){}
	Swap(double c)
	{
		cout << "swap constructor is calling" << endl;
		a = static_cast<int>(c);
		b = 0;
	}
	void show()
	{
		cout << a << ' ' << b << endl;
	}
};
int main()
{
	Swap s1(1,2);
	Swap s2(3.2);
	s1.show();
	s2.show();
	system("pause");
	return 0;
}
           

繼續閱讀