<分区>
Possible Duplicate:
Error on calling default constructor with empty set of brackets
我附上了一个测试程序。 问题:
如果我像下面这样声明,就没有对象被创建并且 不调用默认构造函数。 'grCell c3();'//不好
但是, 像这样声明是可以的。创建一个对象并调用其构造函数。 'grCell c1;'//很好
'grCell c3()' 和 'grCell c1' 有什么区别?
谢谢!
托德
//----开始--------
#include <iostream>
#include <cstdio>
typedef unsigned int uint;
using namespace std;
//
class grCell {
public:
grCell() { printf("HERE_0\n"); };
grCell(int i) { printf("HERE_1\n"); };
~grCell() {};
void setX(int x) { _x = x; }
//
//
private:
int _x:22;
};
int main()
{
grCell c1; // good
c1.setX(100);
grCell c3(); // bad
c3.setX(100);
grCell c2(5);
c2.setX(10);
}
//------ 结束 ------