prototype definition

Discussion in 'C++' started by Carmen Sei, Feb 28, 2008.

  1. Carmen Sei

    Carmen Sei Guest

    http://www.oniva.com/upload/1356/ofAppGlutGlue.h

    from the above .h file, we can see that prototype and definition of
    functions all in same .h file.

    Is that true I can either put everything into .cpp file or put
    everything into .h file

    -OR-

    sepearte them into .h and .cpp file?

    above file seem like a C coding (not in C++) since the function is no
    Class objects, correct?
     
    Carmen Sei, Feb 28, 2008
    #1
    1. Advertising

  2. Carmen Sei

    Amal Guest

    On Feb 28, 7:40 am, Carmen Sei <> wrote:
    > http://www.oniva.com/upload/1356/ofAppGlutGlue.h
    >
    > from the above .h file, we can see that prototype and definition of
    > functions all in same .h file.
    >
    > Is that true I can either put everything into .cpp file or put
    > everything into .h file
    >
    > -OR-
    >
    > sepearte them into .h and .cpp file?
    >
    > above file seem like a C coding (not in C++) since the function is no
    > Class objects, correct?


    > from the above .h file, we can see that prototype and definition of
    > functions all in same .h file.
    >



    > Is that true I can either put everything into .cpp file or put
    > everything into .h file


    It is not an invalid thing if you write everything in a single
    file. But it is a common practice in C++ to write the class
    declaration stuff in .h file and the implementation in .cpp file
    except when you deal with templates.

    > above file seem like a C coding (not in C++) since the function is no
    > Class objects, correct?


    Yea the .h file in that link is C language code. It doesn't use
    the Object concept and it is not an Object oriented language.

    And basically OpenGL is written in C rather than C++.

    Thanks,
    Amal
     
    Amal, Feb 28, 2008
    #2
    1. Advertising

  3. Carmen Sei

    Jim Langston Guest

    Carmen Sei wrote:
    > http://www.oniva.com/upload/1356/ofAppGlutGlue.h
    >
    > from the above .h file, we can see that prototype and definition of
    > functions all in same .h file.
    >
    > Is that true I can either put everything into .cpp file or put
    > everything into .h file
    >
    > -OR-
    >
    > sepearte them into .h and .cpp file?
    >
    > above file seem like a C coding (not in C++) since the function is no
    > Class objects, correct?


    Try to include that same file in two different .c or .cpp files in the same
    project, compile and link. Ooops, errors. Multiple dfinitions of the same
    function(s). Seperate the function defintions into it's own .c or .cpp
    file, include the same header (without the function definitions, just the
    prototypes), compile, link, no errors. The definitions are now only
    declared once.

    --
    Jim Langston
     
    Jim Langston, Feb 28, 2008
    #3
  4. It is really good practice to create a .h for the class declaration
    then only the implementation in a .cpp then the driver or test code in
    another .cpp. It makes the code much more readable.
     
    pleatofthepants, Feb 28, 2008
    #4
  5. Carmen Sei

    Micah Cowan Guest

    Carmen Sei wrote:
    > http://www.oniva.com/upload/1356/ofAppGlutGlue.h
    >
    > from the above .h file, we can see that prototype and definition of
    > functions all in same .h file.
    >
    > Is that true I can either put everything into .cpp file or put
    > everything into .h file
    >
    > -OR-
    >
    > sepearte them into .h and .cpp file?


    It's not true. Classes which contain all the definitions for its members
    within the definition of the class itself, can appear in an .h file
    without an accompanying .cpp file. Templates frequently don't have
    corresponding .cpp files.

    ....however, _this_ .h file includes function definitions.

    That's not a problem per se, but .h are typically intended to be
    #included by multiple .cpp files for the same program. This obviously
    can't happen for this .h file, or there will be multiple-definition
    problems at link time.

    > above file seem like a C coding (not in C++) since the function is no
    > Class objects, correct?


    The file seems to consist of that common subset between C and C++.
    Though the //-style comments would not be extremely portable in C code.
    If constructs such as

    OFSAptr->keyPressed((key | OF_KEY_MODIFIER));

    indicate that OFSAptr (which does not appear to be defined in this .h
    file) points at a class with methods, then I'd say that makes it C++. :)
    But of course, it could point at a C struct with pointer-to-function
    members, too.

    --
    Micah J. Cowan
    Programmer, musician, typesetting enthusiast, gamer...
    http://micah.cowan.name/
     
    Micah Cowan, Feb 28, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Harrison
    Replies:
    4
    Views:
    481
    John Harrison
    Aug 7, 2003
  2. June Lee
    Replies:
    2
    Views:
    810
    Jim Cobban
    Apr 13, 2008
  3. Replies:
    9
    Views:
    206
    Thomas 'PointedEars' Lahn
    May 26, 2006
  4. Replies:
    3
    Views:
    273
  5. javascript fish
    Replies:
    0
    Views:
    177
    javascript fish
    Oct 11, 2008
Loading...

Share This Page