In C++, we know that given a class pointer, we use the (->) arrow operator to access the members of that class, as seen here:
#include <iostream>
using namespace std;
class myclass{
private:
int a,b;
public:
void setdata(int i,int j){
a=i;
b=j;
}
};
int main() {
myclass *p;
p = new myclass;
p->setdata(5,6);
return 0;
}
Then I create an array of myclass.
p=new myclass[10];
when I go to access myclass members through (->) arrow operator, I get the following error:
base operand of '->' has non-pointer type 'myclass'
However, when I access class members using the (.) operator, it works.
These are the things that perplex me. Why do I have to use the (.) operator for a class array?