I'm declaring objects of a struct inside of a function and i'd like to access said objects outside of that function (making them global). Here's an example of what i'd like to do
#include <iostream>
using namespace std;
struct exampleStruct
{
int ID;
};
void makeExampleStruct ()
{
exampleStruct exampleObj[30];
for (int r=0;r<=30;r++)
{
exampleObj[r].ID=r;
}
}
int main()
{
makeExampleStruct();
cout << exampleObj[1].ID << endl;
return 0;
}
This gives me a "'exampleObj' was not declared in this scope". I know i could simply declare the objects creation inside of main, but i'd rather keep it inside of a function so it's easier to read. Is there a way of doing that?
Thank you for your help