explicit 只对构造函数起作用,用来抑制隐式转换。

class A
{
private:
	int a;
public:
	A(int x) :a(x){}
	void display(){ cout << a << endl; }
	void display()const{ cout << "ddd" << endl; }
};

void f(A a)//因为下面数据是常量,不能用&;因为用const就不能使用display
{
	a.display();
}
int main()
{
	A a(2),A  b('a');//隐式转换
	f('3');//隐式转换
	f(2);//影视转换
	A c = 13;//隐式转换
	a.display();
	b.display();
	c.display();
}

  

posted on 2016-06-15 15:19  Kooing  阅读(176)  评论(0编辑  收藏  举报

导航