structs

Associate
Joined
10 Nov 2007
Posts
809
Location
Southampton
hi

i have an odd problem which i cannot see the answer to and was wondering if someone could help

i have a struct in a header file

Code:
typedef struct simple{
int x;
int y;
float z;
simple *next;
}simple;

extern simple * firstSimple

for some weird reason it compiles then wont let me create the linked list

Code:
void add(list of params same as thos in struct other than pointer)
{
if (firstSimple == null)
{
 simple current = new Simple()
simple->x=x;
same for other variables

firstSimple = current}
else{
polygon * eol;
eol = firstSimple;
while (eol.next != NULL)
{eol = eol.next;}
eol.next = new simple()
eol.next->x=x;
...
...
}
}

at the end of it all i get numerous errors the main one being

error c2232 left operand has struct type use '.'

and

error c2228 left of .next must have class/struct/union

then it says at th end fatal error c1903 unable to recover from previous error(s) stopping compilation

if anyone can help me with my simple problem id be very thankfull

thanks in advance
pcdave

[/CODE]
 
simple current = new Simple()
simple->x=x;

I dont think these lines are right. It should be a small S for simple unless you have a different simple with a capital s defined somewhere else. Also, simple is not an object so I dont know what you are doing simple->x = x, I think it should be current->x = x.
 
hi ive made the changes however i think the compiler is stupid as its now saying NULL is an undeclared identifier then it says it cannot convert simple to simple when i create a new object of the struct in c++ and it still says simple does not have an overload member 'operator->

i know this is simple but im getting very confused any help would be much welcomed
 
edit. sorry misread the eol is a pointer to a polygon. I dont think the pointer is set up right however as your not assigning an address of anything to it. Also, why are you assigning something of type simple to something of type polygon?
 
Last edited:
Back
Top Bottom