Re: Which is the better way to define methods?
From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 07/08/04
- Next message: Evan Carew: "Re: How to read multiple items using read ifstream in C++"
- Previous message: Blue Ocean: "Re: Is there anything in C++ akin to Java's class Object?"
- In reply to: Blue Ocean: "Re: Which is the better way to define methods?"
- Next in thread: Ivan Vecerina: "Re: Which is the better way to define methods?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 07 Jul 2004 19:37:52 -0700
Blue Ocean wrote:
> E. Robert Tisdale wrote:
>
[snip]
>>
>>You need to *unlearn* your Java habits.
>>If you define constructors, functions or operators
>>within the class definition, they are inline functions.
>>You can move the function definition out of the class definition
>>but you must qualify it with the 'inline' keyword
>>or move the definition into a separate *implementation* source file
>>where it will be compiled exactly *once*!
>
> So . . . I wasn't thinking at all about inline functions.
> If a method is defined inside the class definition, that's what happens?
> So, tell me if this is right (for normal, non-inlined methods:
>
>
> ========================================
#ifndef guard_file_h
#define guard_file_h
> // file.h
>
> class Stack {
> private:
> int somethingoranother;
>
> public:
> Stack(void);
> ~Stack(void);
> int foo(double bar);
> };
>
#endif// guard_file_h
> // file.cpp
#include "file.h"
>
> int Stack::foo(double bar) {
> // Behavior
> }
>
> Stack::Stack(void) {
> // Behavior
> }
> ========================================
>
> If that is right, let me extend the question a little.
> Should I declare private methods in the .h file?
> Or should I declare them in the .c file?
You must *declare* them in the class definition.
You may *define* them in the header file as *inline* functions.
- Next message: Evan Carew: "Re: How to read multiple items using read ifstream in C++"
- Previous message: Blue Ocean: "Re: Is there anything in C++ akin to Java's class Object?"
- In reply to: Blue Ocean: "Re: Which is the better way to define methods?"
- Next in thread: Ivan Vecerina: "Re: Which is the better way to define methods?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|