为什么for循环,有关p的提示:表达式必须包含指针类型?
#include<stdlib.h>
#include<iostream>
class Coordinate
{
public:
int x;
int y;
void printX()
{
std::cout << x << std::endl;
}
void printY()
{
std::cout << y << std::endl;
}
};
int main(void)
{
Coordinate coor; //用栈实例化对象
coor.x = 10; //用栈访问对象
coor.y = 20;
coor.printX();
coor.printY();
Coordinate *p = new Coordinate[5];
if (p = NULL)
{
return 0;
}
for (int i = 0; i < 5; i++)
{
p[i]->x = 0;
p[i]->y = 2;
p[i]->printX();
p[i]->printY();
}
delete[]p;
p = NULL;
std::system("pause");
return 0;
}