this sounds silly, but some reason (which i can't spot) when i declrare an array of simple structs on the free store, in the following program i can't access them through (->) derefrerencing a pointer instead it only let's use the dot operator (.)...
Code:
#include<iostream>
using namespace std;
struct node
{
int data;
};
int main()
{
int size;
cout << "Enter the size: ";
cin >> size;
node *ptr = new node[size];
for(int i = 0; i < size; i++)
{
cin >> ptr[i]->data;
}
for(i = 0; i < size; i++)
{
cout << ptr[i]->data;
}
return 0;
}
i don't think i'm making a mistake when it comes time to declaring an array dynamically, however the problem pertains to the 2 (for) loops by trying to access (ptr[i]->data)....the only way to compile it is to use the (.) dot operator, but as my memory serves me correctly i'm supposed to use (->) when i try to access data through the pointer...weird....???
hmmm.... either i haven't done this stuff for a while or i just don't see it....
any help would be appreciated...
matheo917