64,661
社区成员
发帖
与我相关
我的任务
分享
#include <IOSTREAM>
using namespace std;
class A
{
public:
explicit A(const char c)
{
cout<<"构造函数"<<endl;
}
A(const A& a)
{
cout<<"拷贝构造函数"<<endl;
}
};
int main()
{
char c = 0;
A a = c; //这里编译错误:cannot convert from 'char' to 'class A',
//A a(c);正常,为什么?
return 0;
}
class X {
// ...
public:
X(int);
X(const char*, int =0);
};
void f(X arg)
{
X a = 1; // a = X(1)
X b = "Jessie"; // b = X("Jessie",0)
a = 2; // a = X(2)
f(3); // f(X(3))
}
int a ;
double b;
a = b;