本想做一个关于无名对象的练习,但是又出现了临时对象的问题.
//本想做一个关于无名对象的练习,但是又出现了临时对象的问题.
#include <iostream.h>
class test
{
static int x;
int y;
test(test &);
public:
test(int Y=0);
~test();
};
test::test(int Y)
{
y=Y;
cout<<"object "<<++x<<"construct\n";
}
test::~test()
{
cout<<"object "<<x++<<"destruct.\n";
}
int test::x=0;
main()
{
test &refs=test(8);//这个程序为什么会出现临时对象?我只是想创建一个无名对象.
return 0; //另外,如果这个类的构造函数是无参的,那创建无名对象的语法是什
么?
} //如果写成test();就变成函数了,难道写成只要test吗?