My code was giving the wrong answer so I thinned it down to this. When my variable arrayCounter=0, then it returns the correct answer in the array. But when arrayCounter=1, I get the incorrect answer of 0.
#include <iostream>
using namespace std;
struct base
{
int x,y;
};
struct myStruct : base
{
char c;
int numOne;
}; myStruct MS[10]; //array of myStruct
base * returnArray(char c) //function that returns array type
{
if(c=='m'){ return MS;}
//I plan to have other structs here similar to myStruct.
}
int main()
{
MS[0].x=204; //init 0 value in array
MS[1].x=97; //init 1 value in array
int arrayCounter=0; //count through array. if=0, returns correctly. If=1, then not correct...
cout<<returnArray('m')[arrayCounter].x<<endl; //MS[1].x=204, MS[1].x=0
system("pause");
}