explicit???
#include <iostream>
using namespace std;
class one
{
public:
one()
{cout << "one constructor" << endl;}
};
class two
{
public:
two(const one&) //explicit two(const one&)
{
cout << "two constructor" << endl;
}
};
void f(two)
{
}
int main()
{
one a;
f(a);//f(two(a))
system("pause");
return 0;
}
问题:
1、书上说上面这段代码的代价是隐藏了构造函数对two的调用
应该将two(const one&) ==〉explicit two(const one&)
f(a) ==〉f(two(a)),可是他们的输出都是:
one constructor
two constructor
我不太理解这段话的意思!!!
2、explicit是什么意思?为什么使用它后,只能将f(a) ==〉f(two(a))