C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old June 10th, 2003, 08:12 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,172 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
Quote:
Originally posted by 3dfxMM
The snippet you quoted about the class having a single header file doesn't imply that the code should be in that file.
That's what I was trying to clarify. You say "the code" shouldn't be in that file. What code?

For example, AGibel puts a class in a header file and that class has methods that can manipulate a graph. He instantiates the object in his .cpp file and invokes the method from the .cpp file. But the code that actually "manipulates the form object" (the graph) is in the header file, right?

All I was doing was trying to restate his question to get a better picture of what he's trying to do and what other posters were trying to tell him to do. I wanted to make sure we weren't giving him bad advice because we misunderstood his intentions. Since dwise1_aol was telling him that "code-in-the-header malarky" was not a good thing, I just wanted to make sure we were all talking about the same code. Some code should go in the header, so what exact code are we discussing here?

Since AGibel is somewhat new to this, I was worried I might be getting confused by some of the syntax being used.

Reply With Quote
  #17  
Old June 10th, 2003, 10:06 PM
AGibel's Avatar
AGibel AGibel is offline
Bad Andy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: OH
Posts: 275 AGibel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 55 sec
Reputation Power: 10
dcaillouet, you definately hit the nail on the head. Sorry if I was vauge before. He's right though, that was the gist of the question. Again, thanks to everyone for thier helpful comments. I have tried many forums before and have found the moderators and posters to be power hungry children with the same or less experiece as myself. So, I will continue playing w/ options etc. In fact, I just got NASA to buy a C++ builder 5 dev book for me so ill have some light reading for a while. Thanks again.

Reply With Quote
  #18  
Old June 10th, 2003, 10:56 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 52 m 21 sec
Reputation Power: 1974
Quote:
Originally posted by dcaillouet
That's what I was trying to clarify. You say "the code" shouldn't be in that file. What code?

"Code" as in "executable code".

Basically, a function consists of a header and a body. The header is the function name, parameter list, and return type. The body is surrounded by braces (i.e. { } ) and contains the executable code, the statements that get compiled into machine instructions. The function header can be put in a header file (did I just stumble onto the origin of that name?) in the form of a function prototype, but the function body should not -- except in rare cases such as inline functions.

The methods in a class declaration are prototypes. Yes they belong there. But the actual method implementation, body containing executable code and all, does not belong in the header file. Except for inline functions.

Reply With Quote
  #19  
Old June 11th, 2003, 07:22 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,172 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
I think I understand now. If he wanted to create a class to manipulate his graphs he would need two files (something like):

GraphManip.h
GraphManip.cpp

GraphManip.h would declare the class and list all the methods as prototypes. The actual implementation of the methods would be in GraphManip.cpp.

He would then need to include GraphManip.h in any forms he wanted to manipulate a graph and also in GraphManip.cpp. The basic concept would be to separate the interface from the implementation.

Reply With Quote
  #20  
Old June 11th, 2003, 08:15 AM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 272 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 17 h 57 m 24 sec
Reputation Power: 17
Ding, ding, ding! We have a winner!

Reply With Quote
  #21  
Old June 11th, 2003, 09:45 AM
AGibel's Avatar
AGibel AGibel is offline
Bad Andy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: OH
Posts: 275 AGibel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 55 sec
Reputation Power: 10
hmm. Anyone know where I can find a sample of such implementation?

Reply With Quote
  #22  
Old June 11th, 2003, 10:23 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 52 m 21 sec
Reputation Power: 1974
Quote:
Originally posted by AGibel
hmm. Anyone know where I can find a sample of such implementation?

I've attached a WinZIPped sample of a Visual C++ app that I was using to test some sockets and telnet code I was researching and developing at the time. It also includes some .c and .h files that I was only using for research purposes and that were not included in the project.

Of course, the project itself will be of little use for you unless someone there has Visual C++ v6 loaded on their machine. However, you can still view the source and header files with a text editor. In particular, check out the .cpp/.h pairs that share the same file name but have different extensions. Those would illustrate the point.

You should also be able to create samples yourself with C++Builder. At least, I assume that it will take the same basic approach as VC++ regarding the creation of classes. In VC++, when you create a new dialog in the graphical resource editor and then use the Class Wizard to add properties and methods (this is very VC++-specific), then it creates a new dialog class and creates a .cpp/.h pair of source files for it. As you add properties and event-handler methods, VC++ updates these two files.

C++Builder should do something very similar to this. I'm sure that in its tutorial or "getting started" manual it takes you through the creation of a new project.

BTW, I haven't had a chance to read those CoreLinux C++ guidelines yet. I'd just like to point out that the standard that dcaillouet cited, that each class have its own header file, is followed by VC++'s automatic creation of a separate source and header file for each class created.

NOTES:
A class' properties may themselves be classes. So of course for that class declaration to compile, its properties' header files must be included before this header file. You can do that by being careful with the order of header-file inclusion in every .cpp source file. An easier way would be to place the necessary includes in your class' header file. The guard-defines will prevent those headers from being included more than once per module.

However, it can happen that two classes need to reference each other or somehow be caught in a circular-referential chain, so that there is no possible way to put the includes in a right order. Or, you may want a class to have a particular property, but you don't want to have to pull in a whole chain of declarations with it. One trick I learned for handling this is to make the property a pointer to that class and to forward-declare that name to be a class, but without the rest of the declaration. Then the rest gets handled in the .cpp file when you new an object of that class. E.g.:
Code:
// first, the guard-define
#ifndef _FIRSTCLASS_H_
#define _FIRSTCLASS_H_

// the forward-declaration
// establishes only that the identifier, SecondClass, is a class, which is enough for now
// note that this would not work for a non-pointer 
class SecondClass;

class FirstClass
{
private:
    SecondClass *sec_class;

public:
    FirstClass(void);
    ~FirstClass(void);
};

#endif
Attached Files
File Type: zip telnettest.zip (81.5 KB, 333 views)

Last edited by dwise1_aol : June 11th, 2003 at 10:53 AM.

Reply With Quote
  #23  
Old June 11th, 2003, 10:30 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,172 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
FYI: VC++ to BCPPB

In Borland C++ Builder under the Tools menu there is a Visual C++ Project Conversion Utility so you can run his code.

Reply With Quote
  #24  
Old June 11th, 2003, 10:57 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,172 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
Take a look at Section 6.7 of the following file:

ftp://ftp.prenhall.com/pub/esm/samp.../cpphtp3_06.pdf

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Borland C++ header files

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap