Jonas I must thank you for helping me. Ok I changed mygetch.h to a cpp file. included it in ascii. Now i'm just left with the same thing before "undefined reference"
I'm not sure what you meant by include braces mainzmenu::mainmenu{}
Jonas I must thank you for helping me. Ok I changed mygetch.h to a cpp file. included it in ascii. Now i'm just left with the same thing before "undefined reference"
I'm not sure what you meant by include braces mainzmenu::mainmenu{}
[QUOTE=Ghostmn;10659236]Jonas I must thank you for helping me. Ok I changed mygetch.h to a cpp file. included it in ascii. Now i'm just left with the same thing before "undefined reference"
Errr... Forget I said that about the {}. Its not required for the switch case. http://www.cplusplus.com/doc/tutorial/control/ I just like to use them but it's not required.
I think the root of your problems is that you have you mygetch defined as a function and not as a class. When you have implementation code in a header weird things happen. If you have it in a cpp,the other functions won't find it. You should be able to globally define a function, but I'm brain farting on that at the moment. Plus I think globally defining stuff is generally looked down upon.
I think your heading with this is that your going to want keyboard input with out a carriage return eventually..
But since your doing a carriage return at the moment perhaps something like this might work.
This was a easy way to read the whole line and just read the first character. It's somewhat bullet proof your app in case someone decides to enter more than one character. Brains are gone... Need to get to bed.. Sorry.Code:#include "employee.h" #include <fstream> #include <iostream> int main() { payroll proll; string initialEmployeeFileName; string line; cout << "Please enter initial employee data file:"; //initialEmployeeFileName="payroll.dat"; getline(cin,initialEmployeeFileName); cout << initialEmployeeFileName << endl; ifstream employeeIDDataFile(initialEmployeeFileName.c_str()); if (employeeIDDataFile.is_open()) { employee temp; while (employeeIDDataFile.good() ) { employeeIDDataFile>>temp; proll.employeeHire(temp); } employeeIDDataFile.close(); //cout<<proll.displayAllEmployeeData(false,true); cout <<"##########################################\n"; cout <<"EMPLOYEE DATA FILE HAS BEEN READ IN \n"; cout <<"##########################################\n"; } else { cout << "Unable to open "<< initialEmployeeFileName <<endl; return 0; } string programOption; do { cout << "**** Payroll Menu *****\n"; cout <<"1. Process Weekly File\n"; cout <<"2. Print Out Payroll\n"; cout <<"3. Exit"<<endl; cout <<"Enter your choice:"; getline(cin,programOption); //cout <<programOption.length()<<endl; switch (programOption[0]) { case '1': { string filename ; cout << "Please enter the file name for the weekly input file:"; getline(cin,filename); //cout <<filename<<endl; proll.clearWeeklyPayRollData(); try { proll.readWeeklyPayrollFile(filename); } catch (const rangeError &re) { cerr<<re.what() << endl; } proll.sortEmployeesbySSN(); break; } case '2': { cout<<"Do you wish to print to file (y\\n):"; string print2file; getline(cin,print2file); switch (print2file[0]) { case 'y': case 'Y': { cout<<"Please enter your output filename:"; string outputfilename; getline(cin,outputfilename); ofstream outputDataStream(outputfilename.c_str()); outputDataStream<<proll.displayAllEmployeeData(false,false); break; } default: { bool boolDisplayLaborDetail =false; bool boolDisplayNoLabor =false; string StrDisplayLaborTransaction; cout <<"\n Would you like to see individual Labor Transactions? (y\\n)"; getline(cin,StrDisplayLaborTransaction); switch (StrDisplayLaborTransaction[0]) { case 'Y': case 'y': { boolDisplayLaborDetail =true; break; } } string StrShowNoLabor; cout <<"\n Include Employees with no Labor? (y\\n)"; getline(cin,StrShowNoLabor); switch (StrShowNoLabor[0]) { case 'Y': case 'y': { boolDisplayNoLabor =true; break; } } cout<<proll.displayAllEmployeeData(boolDisplayLaborDetail,boolDisplayNoLabor ); break; } } } case '3': { break; } default: { break; } } } while (programOption[0]!='3');
Last edited by Jonas thomas; April 10th, 2011 at 07:13 AM.
Defining functions in the header is not the greatest idea, unless you plan on making them inline (i.e. inline int mygetch() {...}). If you include it from several cpp-files you will end up with multiple definitions of the same function which will cause trouble for the linker, hence the "multiple definition"-errors.
You should split the declaration and definition instead, in your case you would simply need to rename your .h-file .cpp and create a new mygetch.h
N.B. The reason why it is possible to define functions in c++ class declarations is that they are implicit inline functions.Code:#ifndef MYGETCH_H #define MYGETCH_H int mygetch(); #endif
Last edited by Linteg; April 10th, 2011 at 09:55 AM.
+1 (wish I said it as eloquently)
Do what he just said and it will bring you to your next error
This is what threw me yesterday night. The program was bombing until I put {} around it (which should not be needed) and moved the error elsewhere. Looking at this a little closer I think what you got going is some type of recursion. For what your doing here, I don't think that's what you want.void mainzmenu::mainmenu(){
std::cout <<
" {}++++++++++++++++{}\n"
" {}=Midnight Cloud={}\n"
" {}++++++++++++++++{}\n"
" Welcome...\n\n"
" ####################\n"
" # #\n"
" # >:New Game:< #\n"
" # #\n"
" # :Load Game: #\n"
" # #\n"
" # :Credits: #\n"
" # #\n"
" ####################\n"
" | Use w and s to |\n"
" | scroll and ENTER |\n"
" | to select |\n"
" ==================\n";
tri=mygetch();
system("clear");
switch (tri){
case 'w':
creditsselect();
break;
case '\n':
//calls for a new game
player newch;
newch.name();
system("clear");
mainmenu();
break;
case 's':
loadselect();
break;
}
mainmenu();
}
Also you may want to rethink what your doing with the
player newch; It looks like it's locally defined. IOW it goes bye bye as soon as the switch goes out of scope.
This stuff... I catch... How to define a simple function... throws me for a loop... Geeez...
Btw... if you guys stick with it you may want to get up your files into separate source and cpp's
something like this: http://code.google.com/p/heekscad/so...%2Ftrunk%2Fsrc
Perhaps find out game on google code and study how they're doing it.
One of the things I have on my todo list is to write a game for my daughter. I've been studying has been this website. http://www.videotutorialsrock.com/. I don't think your ready for that just quite yet. But at some point, it may come in useful.
I haven't really looked into mainmenu, but I've been wanting to change everything into an array like I did in ascii.c++. That would take away the recursion found in mainmenu. Ok so I separated mygetch into a .h .c++. I'll still get "undefined reference" which is interesting since i've only gotten them once i started introducing headers.(read that it isn't recommended to keep everything in a c.++ file) Also moved player newch.
[Edit] I'll take a look at that website once we get into opengl probably won't be until early next year or the year after. Can Someone check my latest build I took care of the recursion found in mainmenu and made it an array (saved 67 lines ^^). I'm working on getting src available on google code so you don't have to download everything. I marked the previous two packages deprecated so you should only see the latest one.
http://code.google.com/p/midnight-cloud/downloads/list
Last edited by Ghostmn; April 10th, 2011 at 07:15 PM.
A little rough, but I seemed to get it running. I added had a weird issue going on(might have been some prior build residue. You may want to consider moving you includes except for the file your working on into your .h
for example in
combat.h just have
#include "combat.h"
In combat.h have:
#ifndef COMBAT_H
#define COMBAT_H
#include <iostream>
#include <cstdlib>
#include <string>
#include "mygetch.h"
#include "enemies.h"
class check0{
private:
void picture(int x);
public:
void combat(int x);
};
#endif
You don't have to do this, but it can prevent some future weirdness from occurring. You'll probably reach a point where you'll need library for your class definition which you will have the definition already there.
Also, may want to consider modifing your function from
void mainzmenu::mainmenu()....
to
char mainzmenu::mainmenu()
Have the function return your choice so you know what to do from there in your main loop.
So move my includes into .h? Do I still leave the includes in the .cpp?
Are you compiling with gcc and not with g++?
Renaming mygetch.h to mygetch.cpp and creating a new mygetch.h as mentioned above, and adding #include "mygetch.h" in Ascii.h was all I needed to make the code compile with:
When I accidentally attempted to compile the code with gcc I did on the other hand get a lot of of "undefined reference" errors regarding functions in the c++ std namepace.Code:g++ -Wall -pedantic -o mc *.c++
Linteg thank you, that helped me compile. Now i can move on with development. Thanks to everyone who gave advice it's all been very helpful.[Edit] Added both of you to the special thanks section in credits, and in the release notes.
Last edited by Ghostmn; April 10th, 2011 at 09:50 PM.
Bookmarks