I have to declare an array of pointers to objects (of classes) in C++. I thought this was the only way, but apparently I was wrong, as it throws a syntax error when I try to compile it. Specifically, among the 7 errors I received, 2 of these errors are in the lines: where I create the array using "new", and in the line where I call the "setData()" function. Can you tell me where I went wrong? Thanks.
#include <iostream>
class Test
{
public:
int x;
Test() { x=0; }
void setData(int n) { x=n; }
};
void main()
{
int n;
Test **a;
cin >> n;
a=new *Test[n];
for(int i=0; i<n; i++)
{
*(a+i)=new Test();
*(a+i)->setData(i*3);
}
}