im making my frist multiple file compilation, and my first .h file of my own. problem is, i dont know where to put struct grades {definition}. no matter which file i put it in, the compiler complains
#include <iostream>#include <fstream>#include "exportimportstructdec.h"usingnamespace std;
struct grades
{
int grade1;
int grade2;
int grade3;
int grade4;
}mygradesi,mygradeso,mygradesa;
//declare pointers to structures for file io:
grades * mygradesptro=&mygradeso;
grades * mygradesptra=&mygradesa;
grades * mygradesptri;
int main ()
{
int choice;
char opfile[]="binary.bin";
char opmessage[]="\nplease enter 4 grades separated by pressing enter\n";
char menu[]="\ndo u want to \n1, read from the file, or \n2, write over the file or \n3, append the file or \n4, exit the program?\n";
//give the user options:do
{
cout<<menu;
cin>>choice;
//option 1, read from the file:if (choice==1)
{
readfilefunc(opfile,mygradesi,mygradesptri);
}
//option 2, write over the file:if (choice==2)
{
wrtfilefunc(opfile,opmessage,mygradeso,mygradesptro);
}
//option 3, append the file:if (choice==3)
{
appfilefunc(opfile,opmessage,mygradesa,mygradesptra);
}
//option 4, exit:
}while (choice!=4);
return 0;
}
#include <iostream>#include <fstream>#include "exportimportstructdec.h"usingnamespace std;
int main ()
{
int choice;
char opfile[]="binary.bin";
char opmessage[]="\nplease enter 4 grades separated by pressing enter\n";
char menu[]="\ndo u want to \n1, read from the file, or \n2, write over the file or \n3, append the file or \n4, exit the program?\n";
//give the user options:do
{
cout<<menu;
cin>>choice;
//option 1, read from the file:if (choice==1)
{
readfilefunc(opfile,mygradesi,mygradesptri);
}
//option 2, write over the file:if (choice==2)
{
wrtfilefunc(opfile,opmessage,mygradeso,mygradesptro);
}
//option 3, append the file:if (choice==3)
{
appfilefunc(opfile,opmessage,mygradesa,mygradesptra);
}
//option 4, exit:
}while (choice!=4);
return 0;
}
Why do you have it defined like that in the first place, or am I missing something here?
1 2 3 4 5 6 7
struct grades
{
int grade1;
int grade2;
int grade3;
int grade4;
}MyGrades, *pMyGrades;
Should be all you need right there. MyGrades being the defined name of the structue and pMyGrades being the pointer to the structure. But hey, maybe I'm missing something but it just doesn't make sense to me. I didn't read the whole code by the way, just that one part you said you were having errors with.
ok, ive taken some suggestions from some people in order to make my code more readable, and ive tried every possible combination of the use of the extern keyword, using it in one cpp file and defining it in anoter, or in the .h... etc, nothing works, im still where i was at my first post. any ideas?
ps: i couldnt fit my whole error report in because of posting rules so i deleted the last few
1>------ Build started: Project: exportstruct, Configuration: Debug Win32 ------ 1>Compiling... 1>exportimportstructdef.cpp 1>c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdef.cpp(27) : error C2027: use of undefined type 'grades' 1> c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdec.h(4) : see declaration of 'grades' 1>c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdef.cpp(28) : error C2512: 'grades' : no appropriate default constructor available 1>c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdef.cpp(39) : error C2036: 'grades *' : unknown size 1>c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdef.cpp(39) : error C2027: use of undefined type 'grades' 1> c:\documents and settings\administrator\my documents\visual studio 2008\projects\exportstruct\exportstruct\exportimportstructdec.h(4) : see
#include <iostream>#include <fstream>#include "exportimportstructdec.h"usingnamespace std;
struct grades
{
int grade1;
int grade2;
int grade3;
int grade4;
}myGradesi,myGradeso,myGradesa;
//declare pointers to structures for file io:
grades * pMyGradeso=&myGradeso;
grades * pMyGradesa=&myGradesa;
grades * pMyGradesi;
int main ()
{
int choice;
char opFile[]="binary.bin";
char opMessage[]="\nplease enter 4 grades separated by pressing enter\n";
char menu[]="\ndo u want to \n1, read from the file, or \n2, write over the file or \n3, append the file or \n4, exit the program?\n";
//give the user options:do
{
cout<<menu;
cin>>choice;
//option 1, read from the file:if (choice==1)
{
readfile(opFile,myGradesi,pMyGradesi);
}
//option 2, write over the file:if (choice==2)
{
wrtfile(opFile,opMessage,myGradeso,pMyGradeso);
}
//option 3, append the file:if (choice==3)
{
appfile(opFile,opMessage,myGradesa,pMyGradesa);
}
//option 4, exit:
}while (choice!=4);
return 0;
}
#include <iostream>#include <fstream>#include "exportimportstructdec.h"usingnamespace std;
grades myGradesi,myGradeso,myGradesa;
//declare pointers to structures for file io:
grades * pMyGradeso=&myGradeso;
grades * pMyGradesa=&myGradesa;
grades * pMyGradesi;
int main ()
{
int choice;
char opFile[]="binary.bin";
char opMessage[]="\nplease enter 4 grades separated by pressing enter\n";
char menu[]="\ndo u want to \n1, read from the file, or \n2, write over the file or \n3, append the file or \n4, exit the program?\n";
//give the user options:do
{
cout<<menu;
cin>>choice;
//option 1, read from the file:if (choice==1)
{
readfile(opFile,myGradesi,pMyGradesi);
}
//option 2, write over the file:if (choice==2)
{
wrtfile(opFile,opMessage,myGradeso,pMyGradeso);
}
//option 3, append the file:if (choice==3)
{
appfile(opFile,opMessage,myGradesa,pMyGradesa);
}
//option 4, exit:
}while (choice!=4);
return 0;
}