Now why didn't *_I_* think of that!
Declarations and Definitions in One Header
C++ object definitions can be quite complex. In principle, your source code
will need two kinds of things for each object that you use across more than
one source file. First, you need an interface specification, describing its
structure with type declarations and function prototypes. Second, you need
the implementation itself. It can be tedious to maintain a separate
interface description in a header file, in parallel to the actual
implementation. It is also dangerous, since separate interface and
implementation definitions may not remain parallel.
http://tinyurl.com/2xx3w
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
|
|
0
|
|
|
|
Reply
|
susudata (549)
|
4/24/2004 11:56:09 PM |
|
They're called "inline" functions.
|
|
0
|
|
|
|
Reply
|
null25 (1553)
|
4/25/2004 8:17:46 AM
|
|
Steven T. Hatton wrote:
> Now why didn't *_I_* think of that!
>
> Declarations and Definitions in One Header
>
> C++ object definitions can be quite complex. In principle, your source code
> will need two kinds of things for each object that you use across more than
> one source file. First, you need an interface specification, describing its
> structure with type declarations and function prototypes. Second, you need
> the implementation itself. It can be tedious to maintain a separate
> interface description in a header file, in parallel to the actual
> implementation. It is also dangerous, since separate interface and
> implementation definitions may not remain parallel.
>
> http://tinyurl.com/2xx3w
>
This is more of a question of style and preference, rather than a
general rule . As a thumb rule, in C++ - the header files are always
separated from source files (with proper header guards that is, in the
header files).
But then you were right when you mentioned about separating interface
and the implementation. Interestingly, Java does not allow you to do
that. When you define classes, you got to write the define the methods
along with the declarations, there is way we can separate them. ( The
'interface' keyword is entirely different though ).
--
Karthik
------
Human Beings please 'removeme' for my email.
|
|
0
|
|
|
|
Reply
|
removeme_kaykaydreamz (133)
|
4/25/2004 8:28:34 AM
|
|
Steven T. Hatton wrote:
> Now why didn't *_I_* think of that!
>
> Declarations and Definitions in One Header
>
> C++ object definitions can be quite complex. In principle, your source
> code will need two kinds of things for each object that you use across
> more than one source file. First, you need an interface specification,
> describing its structure with type declarations and function
> prototypes. Second, you need the implementation itself. It can be
> tedious to maintain a separate interface description in a header file,
> in parallel to the actual implementation.
Actually, I see an advantage in doing that. It's cleaner to separate the
two, IMHO.
> It is also dangerous, since separate interface and implementation
> definitions may not remain parallel.
Why would that be dangerous? If they don't match, the compiler will tell
you so with an error message.
|
|
0
|
|
|
|
Reply
|
ramagnus (3485)
|
4/25/2004 8:41:57 AM
|
|
Karthik wrote:
> Steven T. Hatton wrote:
>> Now why didn't *_I_* think of that!
>> http://tinyurl.com/2xx3w
>
> This is more of a question of style and preference, rather than a
> general rule . As a thumb rule, in C++ - the header files are always
> separated from source files (with proper header guards that is, in the
> header files).
I hope you clicked the link. I should have put quotation marks in the
paragraph. It's from the latest GNU gcc documentation. I didn't write it.
> But then you were right when you mentioned about separating interface
> and the implementation. Interestingly, Java does not allow you to do
> that. When you define classes, you got to write the define the methods
> along with the declarations, there is way we can separate them. ( The
> 'interface' keyword is entirely different though ).
You can separate interface from implementation in Java. AAMOF the official
Java recommendation is this: "Every major class in an application should be
an implementation of some interface that captures the contract of that
class." TJPL(3E) page 105. There are also other strategies such as that
used with JAXB. I find that approach to be far more trouble than it's
worth. For the most part, I believe a properly designed class will provide
its own interface without the need to resort to abstracting it.
There is an advantage to implementing a standardized API in the abstract,
and having various implementations created to back it up.
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
|
|
0
|
|
|
|
Reply
|
susudata (549)
|
4/25/2004 10:24:41 AM
|
|
|
4 Replies
16 Views
(page loaded in 0.067 seconds)
Similiar Articles: header's included but still get 'implicit declaration' - comp.unix ...return 0; } Might be on Linux there is difference in what order the header ... define XString_dot_h_ #include ... and repost the entire class, declaration AND definition. Undefined reference to public class method? - comp.lang.c++ ...... it, add ' #include <string>' and ' using namespace std;' to your header ... may have forgotten to include the c/cpp file in your build, or the declaration and definition ... Define a variable at a fixed address? - comp.compilers.lcc ...... structs defined in other files, and since the header ... file1.h" // contains other variable declarations ... using custom qualifiers/annotations in type definitions ... SystemVerilog - building multiple file hierarchies: include or ...However I believe a package declaration is restricted ... it's like #include-ing a C source (not header ... Keep the source files manageably small (one class definition in ... why fopen64()? - comp.unix.solarisJust reading "man lf64" about the so-called transitional interfaces for largefile-aware 32-bit programs. I do understand why we have stat64() et al:... Neatest way to get the end pointer? - comp.lang.cNULL is declared in many standard C header files, among them is ... const *const pend = my_array + X; The reason for this is: 1) I can't see the declaration or definition ... ntpd IPv6 support on Windows? - comp.protocols.time.ntp... if we build with VC6 without SDK then we have to use the definitions ... on the compiler version instead of checking whether some declarations are available after the header ... C style question - comp.lang.c... which "for faster compilation" has ad hoc declarations of ... I suppose size_t is "type defined in a header", but ... (It's fussier, because I provide *definitions* of my own ... EMSDIST in TACL script. - comp.sys.tandem... are in chapter 14 of the EMS Reference manual (EMS Definitions). In general, tokens stored in the header ... the description and go directly to the subheading "Declarations ... converting C/Visual BASIC code to MATLAB - comp.soft-sys.matlab ...How do I do an external driver function declaration? ... In C, that is a preprocessor definition. The ... expression is an array and has a run-time header that ... 6.4: Declarations and Definitions in One HeaderUsing and Porting GNU CC. 6.4: Declarations and Definitions in One Header. C++ object definitions can be quite complex. In principle, your source code will need two ... Using and Porting the GNU Compiler Collection (GCC): C++ ExtensionsThis header must be the same in all translation units, or things are likely to break. See section Declarations and Definitions in One Header, for more discussion of these ... 7/14/2012 7:12:46 AM
|