Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Nov 29th, 2005, 7:28 PM   #21
teencoder
Hobbyist Programmer
 
teencoder's Avatar
 
Join Date: Jul 2005
Posts: 158
Rep Power: 0 teencoder is an unknown quantity at this point
@DaWei I have seen this done in many of my programming books and yes I am an ameteur but truly it is a copy and paste operation I simply seperate it for my sake in the end it doesn't matter if it is in the original source or not. As for compilers I have a basic understanding of them. The files are compiled seperatly and linking puts them in to one file ultimately it all becomes one eventually.
__________________
Geeks may not be cool now but in the long run they prosper.
teencoder is offline   Reply With Quote
Old Nov 29th, 2005, 7:33 PM   #22
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Toss your books if they recommend code in the header files. This does not apply to class definitions. If you're putting your functions in header files for modularity, you are going about modularity the wrong way. If your personal preference is to do things improperly, that's your business. Please do not spread the poison to new people trying to learn the best ways, not the worst ways.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 29th, 2005, 7:39 PM   #23
B3TA_SCR1PT3R
Hobbyist Programmer
 
B3TA_SCR1PT3R's Avatar
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 101
Rep Power: 0 B3TA_SCR1PT3R is an unknown quantity at this point
Send a message via AIM to B3TA_SCR1PT3R
I dont see what the big problem is, code still works in .h even if it is the wrong type.
If books, and tutorials all do it, its not that bad.
__________________
Hoes telling me to calm down but I'm like fuck that shit!
B3TA_SCR1PT3R is offline   Reply With Quote
Old Nov 29th, 2005, 7:48 PM   #24
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Books and tutorials don't all do it. The problem has been explained here. In code of any complexity if will cause multiple definition errors. Please remove the sack long enough to read the explanations, and please refrain from condoning bad practice.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 30th, 2005, 3:02 AM   #25
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,295
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Polyphemus_
@pharaoh: you put it exactly the other way around: you put the definitions in the header file and the declarations in the source file
Nope. A definition is implicitly a declaration, but not vice-versa. It's much like how a cat is implicitly a mammal, but a mammal isn't necessarily a cat.

Some links are here, here and here.

Declarations: function prototypes, class declarations, variable declarations (ie with extern keyword).

Definitions: function declarations which include a function body, class or variable declarations which associate a name with storage for an object, optionally initializing it.
__________________
Java? Rant? Me? Noooo....
lectricpharaoh is offline   Reply With Quote
Old Nov 30th, 2005, 5:02 AM   #26
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
Lectic read your #14 post again, poly is trying to help
Quote:
First, do not put actual code in header files.
Then look at your example:
// stats.h
// character stats header
 
characterStats :: characterStats(void)
{
strength = 0;
health = 0;
agility = 0;
}
This says stats.h, you meant it to say stats.cpp
__________________
"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 Nov 30th, 2005, 10:45 PM   #27
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,295
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by nnxion
This says stats.h, you meant it to say stats.cpp
Err, yeah. I did cut-and-paste to swap them, but I guess I missed that bit. Point taken.

I was only responding to the definition vs. declaration statement, thinking he meant 'you' as in a generic term for someone, ie 'one puts definitions in header files' (wrong), rather than a direct 'you', referring to my boo-boo, of which I was unaware. Oops.
__________________
Java? Rant? Me? Noooo....
lectricpharaoh 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 10:57 PM.

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