I did include <vector>.
You MUST declare the structure DataLine BEFORE you use it
the struct and the class are defined in the header file. 1st the struct then the class, so it know what DataLine is. If I declare the struct and the class in the main .cpp file without a header file, it runs, but doesn't let me access the members of the struct, Unless I'm doing it wrong:
Code:
#include<cstdio>
#include <vector>
#include <iostream>
using namespace std;
struct DataLine{//everything public by default
char Param[20];
int Label, SFactor, SigBits;
int Bit30, Bit31, Max, Min;
DataLine(){//a REALLY GOOD IDEA to have a constructor initialize variables
Label=SFactor=SigBits=Bit30=Bit31=Max=Min=0;
memset(Param, 0, sizeof(Param));
};
} ;
class FSAD{ //Fixed/Selectable Analog Data
public:
char Name[25];
int nExpected; // size = nExected*2+1
vector < DataLine > vectDL;
//void MakeSec() no need for this now
};
void ReadDataSec(FILE * inp, FSAD &Section , int nExpected)//note that Section MUST be passed in by reference!
{
char line[100];
int i=0;
DataLine dl;
while ( fgets(line, sizeof line, inp) != NULL ) // reads in a line of text from file
{
//if ( strncmp(line, "ENDL", 4) == 0 ) // Exit if at the end of a section
//{
sscanf(line, "%s",dl.Param);
printf("%s \n", dl.Param);
Section.vectDL.push_back(dl);//this does a copy, this could be more efficient with references, but I wouldn't worry about that now.
break;
}
//}
}
int main()
{
FSAD test;
FILE *inp;
inp = fopen("J:\\EICAS Simulator\\Engine Files\\615F.eng", "r");
int n = 16;
ReadDataSec(inp, test, n);
cout<<endl<<test.vectDL.Param<<endl;
return 0;
}
If I use a header file and define the function in its own .cpp file, I get the errors I mentioned before.
Why is it so confused?