Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > prototype definition

Reply
Thread Tools

prototype definition

 
 
Carmen Sei
Guest
Posts: n/a
 
      02-28-2008
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?
 
Reply With Quote
 
 
 
 
Amal
Guest
Posts: n/a
 
      02-28-2008
On Feb 28, 7:40 am, Carmen Sei <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      02-28-2008
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
pleatofthepants
Guest
Posts: n/a
 
      02-28-2008
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.
 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      02-28-2008
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prototype WTP 0.2 released,this release for Prototype 1.6.0 javascript fish Javascript 0 10-11-2008 07:35 AM
Class prototype vs C function prototype June Lee C++ 2 04-13-2008 08:17 PM
Prototype Object.extend(new Base() | Hash | Hash.prototype) usage: jacobstr@gmail.com Javascript 3 03-27-2007 07:56 AM
relation between prototype and Prototype.js shypen42@yahoo.fr Javascript 9 05-26-2006 01:13 AM
prototype declaration not variable definition John Harrison C++ 4 08-07-2003 05:37 AM



Advertisments