Hi,

I want to know if I can use the structure pointer -> to access a structure that is in an array.

currently I am using this:

while (inFile.good()){
	       inFile.getline(cstring,80);
[B]	       (*points[size]).x = strtod(cstring,&pEnd);
	       (*points[size]).y = strtod(pEnd, NULL);[/B]
	       size++;
           
}

points is a pointer to an array of class Point.

how would you write this??
points->y; ??

Recommended Answers

All 4 Replies

use a vector

vector<Point> points;
Point p;
while( inFile >> p.x >> p.y )
{
   points.push_back(p);
}

>>how would you write this??
points->y; ??

Did you try it?

it doesnt work:

I get this from the compiler.
a2.cpp:52: error: base operand of `->' has non-pointer type `Point'

does that mean that I need to overload the operator to work with my class?

>>does that mean that I need to overload the operator to work with my class?

NO absolutely not. DO NOT OVERLOAD THE -> OPERATOR!

The correct syntax in your case is:
points.x

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.