对象数组和对象指针
定义:类名 数组名 [下标表达式]
访问:数组名[下标].成员名
初始化:
class complex
{
public:
complex()
{
cout << "构造函数" << endl;
}
complex(int num):a(num),b(a)
{}
complex(int n1,int n2):a(n1),b(n2)
{}
~complex()
{
cout << "析构函数" << endl;
}
private:
int a;
int b;
};
int main()
{
test1();
complex com[3];//类名 数组名 [下标表达式]
//单参数构造函数
complex com1[3] = { 1,2,3 };
//多参数构造函数
complex com2[3] = {
complex(1,2),
complex(3,2),
complex(4,2)};
return 0;
}
对象指针
类名*对象指针
stack<string>* p = new stack<string>[10];
delete[]p;
类中的this指针
每个对象都有自己的数据成员,但是所有对象的成员函数代码却合用一份,通过this指针来处理,通常this指针时隐含存在的