Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 25th, 2006, 6:10 PM   #1
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4 Soulstorm is on a distinguished road
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...
Attached Files
File Type: zip source.zip (6.8 KB, 17 views)
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote
Old Jun 25th, 2006, 8:06 PM   #2
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3 King is on a distinguished road
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!
King is offline   Reply With Quote
Old Jun 26th, 2006, 3:23 AM   #3
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4 Soulstorm is on a distinguished road
Quote:
...(mostly to do with multiple definitions of things, so probably something to do with the way you have done your includes)
That's what kinds of errors I have. I though putting
#ifndef FILENAME_H
#define FILENAME_H
//code
#endif
Whould work correctly. What have I done wrong in the includes?

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)
Soulstorm is offline   Reply With Quote
Old Jun 26th, 2006, 6:54 AM   #4
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4 Soulstorm is on a distinguished road
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.)
Attached Files
File Type: zip source.zip (4.1 KB, 8 views)
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote
Old Jun 26th, 2006, 7:01 AM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 26th, 2006, 7:22 AM   #6
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 4 Soulstorm is on a distinguished road
Quote:
So is there a problem?
Yes, there is. I haven't been able to clarify yet why I was getting these error messages in the first place. People tell me that I should disable it, if I want to distribute my application. Disabling it, caused me errors with multiple definitions, as described above. I know that since my program work now, I shouldn't dig this thing up more. But I think I'm still missing something important here.

For information about ZeroLink, see here

Quote:
Why use pre-compiled headers?
Well, the obvious answer that comes to my mind is to ask "Why not?" Actually, I used it for these reasons:
--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)
Soulstorm is offline   Reply With Quote
Old Jun 26th, 2006, 10:15 AM   #7
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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.
Game_Ender is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC