The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Page 2 -
Borland C++ header files
Page 2 - Discuss Borland C++ header files in the C Programming forum on Dev Shed. Borland C++ header files C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 10th, 2003, 08:12 PM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
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.
|

June 10th, 2003, 10:06 PM
|
 |
Bad Andy
|
|
Join Date: Jun 2003
Location: OH
Posts: 275
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.
|

June 10th, 2003, 10:56 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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.
|

June 11th, 2003, 07:22 AM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
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.
|

June 11th, 2003, 08:15 AM
|
|
|
|
Ding, ding, ding! We have a winner!
|

June 11th, 2003, 09:45 AM
|
 |
Bad Andy
|
|
Join Date: Jun 2003
Location: OH
Posts: 275
Time spent in forums: 2 m 55 sec
Reputation Power: 10
|
|
|
hmm. Anyone know where I can find a sample of such implementation?
|

June 11th, 2003, 10:23 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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
Last edited by dwise1_aol : June 11th, 2003 at 10:53 AM.
|

June 11th, 2003, 10:30 AM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
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.
|

June 11th, 2003, 10:57 AM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|