On 19 Nov 2005 09:24:08 -0800, "Al" <alberto.bietti@gmail.com> wrote:
[color=blue]
>Do you mean I just need to change the extension for using the header?
>That's better then...[/color]
Headers usually have an extension of *.h or *.hpp, but there may be
others. Typically, only declarations of things (classes, templates,
functions, etc.) are kept in header files. Definitions (i.e. function
bodies, static member data initializers, etc.) are kept in *.cpp
files. This is a fundamental difference (declaration vs. definition)
which you need to know, and I'm sure that the FAQ has something to say
about it.
The big exception to this are template functions and classes: the
definitions (i.e. bodies) of these must be either in the same header
file where the declarations are, or else kept in a separate file but
included at the bottom of the header. If you like to keep the template
function bodies in a separate file, some people like to give it the
extension *.cc to keep it separate from *.cpp files. That way, the
compiler won't try to compile it as a separate translation unit if it
finds the file in the same directory as the *.cpp files. There is also
a new C++ feature cncerning templates using the keyword "export", but
almost nobody uses it yet, so I wouldn't worry about that right now
(you have enough other things to worry about! ;)
[color=blue]
>What is #pragma once and usually #pragma for? The FAQ doesn't tell
>about it[/color]
Well, I already told you what "#pragma once" is for ... just read my
last message again a little more carefully. If you don't use the
Microsoft compiler, you won't need it. But maybe you will want to use
it some day in the future, then you will know what it is about.
In general, #pragma directives are implementation-specific things that
are usually not portable from one compiler to the next. Some #pragmas
are the same between some different compilers (not all) by
coincidence, or perhaps by market strategy, but they don't have to be.
To find out what any specific #pragma directive means, you have to
consult the documentation included with your particular compiler.
Since the C++ standard doesn't have much (if anything) to say about
them, that's probably why they aren't discussed in the FAQ. AFAIK the
standard only requires conforming implementations to ignore unknown
#pragma directives instead of issuing an error. Some compilers will
warn about an unknown #pragma, though.
--
Bob Hairgrove
NoSpamPlease@Home.com