经过测试发现,带参数的构造函数不可以用来声明数组,如下列的代码就是错误的。
class Coordinate {
public:
//Coordinate() {
//}
Coordinate(int x, int y):m_iX(x),m_iY(y)
{
}
Coordinate(const Coordinate & coor) {
this->m_iX = coor.m_iX;
this->m_iY = coor.m_iY;
}
void PrintCoor()
{
cout << m_iX << ',' << m_iY << endl;
}
void PrintCoor()const
{
cout << m_iX << ',' << m_iY << endl;
}
private:
int m_iX;
int m_iY;
};
如果没有默认构造函数,这里将不可以用
Rect arrRect[10];
来声明一个对象数组。必须要有默认构造函数,因为不可以在实例对象数组时为每个元素传入参数,来执行带参构造函数。