Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    31
    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.
  2. #17
  3. Bad Andy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    275
    Rep Power
    13
    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.
  4. #18
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2224
    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.
  6. #19
  7. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    31
    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.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    20
    Ding, ding, ding! We have a winner!
  10. #21
  11. Bad Andy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    275
    Rep Power
    13
    hmm. Anyone know where I can find a sample of such implementation?
  12. #22
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2224
    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
    Last edited by dwise1_aol; June 11th, 2003 at 10:53 AM.
  14. #23
  15. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    31

    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.
  16. #24
  17. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    31
    Take a look at Section 6.7 of the following file:

    ftp://ftp.prenhall.com/pub/esm/sampl...cpphtp3_06.pdf
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo