Ok I have my structure defined in my main function.
And the I need to send an array of structures to a function as follows:

int fillStruct (ifstream& fin, ROPES ropes[MAXROPES], int n)

int main()
{
struct ROPES
{
members
};
return0;
}

int fillStructs (ifstream& fin, ROPES ropes[MAXROPES], int n)

The problem is when I put the ROPES ropes[MAXROPES] in the prototype of the function, it says ROPES is not defined. do I have to define the structure globally? and if so do I have to define all it's members globally? Should I be sending the members to the function as well?

You don't have to specify an array's upperbound if you pass it to a function int fillStruct (ifstream& fin, ROPES ropes[MAXROPES], int n) change it to int fillStruct (ifstream& fin, ROPES ropes[], int n)

I know. It's optional though, and I usually do it. But that doesn't really help with my problem. It's still saying ROPES was not declared

>>do I have to define the structure globally?
No just declare it globaly. Like this

struct ROPES;
int fillStruct (ifstream& fin, ROPES ropes[], int n);

int main()
{
struct ROPES
{
members
};
return0;
}

int fillStructs (ifstream& fin, ROPES ropes[], int n)
{}

I know. It's optional though, and I usually do it. But that doesn't really help with my problem. It's still saying ROPES was not declared

Try declaring ROPES globally :)

>>do I have to define the structure globally?
No just declare it globaly. Like this

struct ROPES;
int fillStruct (ifstream& fin, ROPES ropes[], int n);

int main()
{
struct ROPES
{
members
};
return0;
}

int fillStructs (ifstream& fin, ROPES ropes[], int n)
{}

program6.cc: In function âint fillStruct(std::ifstream&, ROPES*, int)â:
program6.cc:65: error: invalid use of undefined type âstruct ROPESâ
program6.cc:9: error: forward declaration of âstruct ROPESâ
program6.cc:65: error: invalid use of undefined type âstruct ROPESâ


That's one set of about 50 errors I'm getting. it seems everytime I reference the structure I get an error

Try doing it in the following way:

struct ROPES
{
    /* members */
};

int fillStruct (ifstream& fin, ROPES ropes[], int n);

int main()
{
    /* Your code */
    return 0;
}

int fillStructs (ifstream& fin, ROPES ropes[], int n) {
    /* Your code */
}

Thanks so much! that worked. You're awesome

The last question: where is Modular Programming in OP snippet? ;)

>>The last question: where is Modular Programming in OP snippet?
You're with me. Lets open a new thread and discuss it !! LOL
(This means that even I don't know where does Modular Programming comes into play)

It seems I understand: at first OP incapsulated struct definition deeply into the main body (that's one of the most valued modular programming principle). After that he/she was wondered that an outer function needs this definition but can't see it (i.e. modular programming principles work in C++). The happy end: that damned structure definition is public now. Moral of a story: a modular programming considered harmful...

>>The happy end: that damned structure definition is public now.
This was one of the trivial solution. I was looking forward to do something 'good'(like forward declaration). Alas, it didn't worked.

>>Moral of a story: a modular programming considered harmful...
Are you sure?

If it was the true modular programming issue then yes, it's the only reasonable conclusion ;)
Better ask David Parnas...

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.