prototype definition

C

Carmen Sei

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?
 
A

Amal

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
 
J

Jim Langston

Carmen said:
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.
 
P

pleatofthepants

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.
 
M

Micah Cowan

Carmen said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top