0

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; ??

Edited by Dazaa: n/a

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by mike_2000_17
0

use a vector

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

Edited by Ancient Dragon: n/a

0

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?

0

>>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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.