![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4
![]() |
C++ bankAccount problem
Here is the full source of the program.
When I try to compile the program using Dev C++, it gives me errors and warnings everywhere, although the program compiles and runs perfectly under OS X (I have not used any OS specific routines). In OS X, it compiles perfectly with ZeroLink turned on. When I turn it off, it doesn't let me compile the program, because it states that I have "multiple declarations of _bank" (I have no such variable in my program). 1) In OS X I use Xcode 2.3 (with GCC 4.0), while DevC++ uses GCC 3. Perhaps this is the reason why it gives me those errors? 2)What is the ZeroLink anyway? Why do people recommend me to turn it off, and why the default is on? What can I do to fix the problem of the multiple declarations of a variable that I have not declared? Can anyone have a look at my program, because I am very confused...
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3
![]() |
I downloaded the files and tried to compile it in Linux under GCC4. It was giving a bunch of errors about not having a "newline" at the end of the file, so I put a blank line at the end of each of the files and that fixed all the warnings... then it had an error in the main saying it couldn't fine "Floader.h", and that was because you spelled it wrong, it should be "FLoader.h". Then when I fixed that error it gave me about 30 more errors (mostly to do with multiple definitions of things, so probably something to do with the way you have done your includes) and that’s as far as I got... hope that helps a bit. Also compiling a program that was written in GCC4 under GCC3 could give errors, so you should upgrade your DevC++ to GCC4 just to make sure that isn't that problem (I don’t use DevC++ so I don't know if you can do that).
__________________
I am Addicted to Linux! |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4
![]() |
Quote:
#ifndef FILENAME_H #define FILENAME_H //code #endif Damn. Trying to upgrade programs you have written one year ago is a real pain in the *ss. Probably, I would do it a completely different way if I wrote it now..
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4
![]() |
Hm... I was forced to rewrite the whole application from scratch using classes. Here is what I have got:
It seems that now I haven't got these zero-link errors... I used a pre-compiled header this time. I would appreciate it if you had a look at it and tell me if that was the best way of doing it (the program is MUCH smaller and comprehensive, compared to the last one.)
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
So is there a problem? Why use pre-compiled headers?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#6 | ||
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4
![]() |
Quote:
For information about ZeroLink, see here Quote:
--I wanted to see how .pch work and what's their use. --I didn't want to be forced to include all the necessary libraries into each source document in my project. I found it easier to just write them all in one place, then do what else I want in the rest of the project Is there any particular reason for not using it? So, my questions are: --Why did I get those error messages in my first post (I'm terribly sorry for the code. It may ruin your eyes , but I wrote it one year ago, when I started learning C++). King saw these problems too, so it's not a ZeroLink thing, it's my fault.--Is the code in the last program I uploaded tidy? Do I need to make some changes? It works OK, but I just want someone to tell me if I have included everything correctly and used the preprocessor the right way --Last but not least (but somewhat irrelevant): What's the difference between writing code in header files and writing in .cpp files? Why shouldn't I put all the definition and the declaration of a class in the .h file?
__________________
Project::Soulstorm (personal homepage) |
||
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
Its all about removing compilation dependencies, which is why you use pch in the first place. If all your code is in your header file, then every time you change how anyone of your functions works you have to recompile every file that uses your class. If you keep the interface to your class in the header file, and the implementation in the cpp file then you remove that dependency.
I think it is good practice to make sure you project compiles without pch because not all compilers support pch. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|