int b;
int c;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << &b << endl;
int b(b);
cout << &b << endl;
cout << "--------------------" << endl;
cout << &c << endl;
int c = c; //到这里程序崩溃
cout << &c << endl;
system("pause");
return 0;
}
程序运行到int c = c时崩溃,百思不得其解,用类实验了一下
class a
{
public:
a(const a & t)
{
cout << &t << endl;
}
a()
{
}
};
a i;
a x;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 0xf << endl;
cout << hex <<&i << endl;
a i(i);
cout << &i << endl;
cout << "---------------------" << endl;
cout <<&x << endl;
a x = x;
cout << &x << endl;
system("pause");
return 0;
}
类的代码段程序运行没有问题。
问题有两点:
1、int c(c);在C++中是怎么实现的,是对int进行了封装使其调用构造函数吗
2、int c = c;为什么会崩溃