Re: Is it necessary to declare the private section of a C++ class?
On Sep 14, 1:32 pm, Rune Allnor <all...@tele.ntnu.no> wrote:
On 14 Sep, 09:04, Ramon F Herrera <ra...@conexus.net> wrote:
In this BOOK that I am READING, the author declares the
whole enchilada, and I don't understand why.
From the point of view of an author who writes about the C++
language in general (as opposed on any particular system /
implementation), this structure makes a lot of sense since his
focus is on how to structure the classes etc, not the source
code. The exact voodoo needed (or preferred) to structure the
source code properly varies a bit from system to system.
Not really. How to invoke the compiler varies immensely from
system to system, but even how to tell it how to find the
necessary parts is in practice very similar from one compiler to
the next. (Almost always a -I or /I for specifying include
paths, for example.)
MS Visual Studio needs - surprise... - some proprietary
stuff in addition to the standard way of doing things,
Bullshit. I recently ported a very large chunk of C++ developed
under Unix to Windows VC++, and changed absolutely nothing in my
file organization. If you're doing system dependent code,
you'll need to include different system headers, of
course---<unistd.h> will get you about as far under Windows as
<windows.h> does under Unix. But all of the rest is identical.
Apart from that, C++ template programming is implemented only
in .h files:
It depends. My template implementations are in .tcc files. At
any rate, the code in question wasn't template code. And of
course, if the implementation is standard compliant (e.g. like
Comeau), then you can put the template implementation directly
in the source files where it belongs.
[...]
And of course, there are limitations: Executable code
that relies on pre-compiled linkable components should
*not* be called in .h files.
It's not clear what you mean here. Code which depends on
another library follows the same rules as any other code.
[...]
With with pre-compiled linkable libraries, you can do exactly
like you want: The user has no business knowing what goes on
inside the component, so in that case it is prefectly possible
to supply a .h file that only declares the public interface.
The class definitions must be complete (in the header file) if
the client code is to instantiate instances of the class.
Including any private members.
--
James Kanze