Re: confusion with copy constructor and operator overloading
From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 02/09/05
- Next message: Ron Natalie: "Re: why .hpp?"
- Previous message: E. Robert Tisdale: "Re: const in headers"
- In reply to: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Next in thread: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Reply: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 09 Feb 2005 12:38:38 -0800
Kelly Mandrake wrote:
> Ok I see now what you mean that you simply added the keywords inline.
> I've been putting the definitions inside my class alot too.
So do I if the class definition is short (less than a page).
But, if the class definition becomes very long,
I move constructor, operator and member and frient function definitions
(usually all of them) out of the class definition.
This also allows me to reorder these definitions
so that inline member functions are defined
before other member functions that use them.
> So these are considered light weight
> because they only have a few lines. Or is there a rule of thumb
> to determine weather to make them inline or not.
Actually, I don't worry about this.
inline function slow down compilation
and, consequently, the code-compile-test-debug development cycle
so I arrange my code so that I can build with either inline or external
function definitions:
> cat file.h
#ifndef GUARD_FILE_H
#define GUARD_FILE_H 1
#ifdef EFINE_INLINE
inline
double dot(const double x[], const double y[], int n) {
double t = 0.0;
for (int j = 0; j < n; ++j)
t += x[j]*y[j];
return t;
}
#else //EFINE_INLINE
double dot(const double x[], const double y[], int n);
#endif//EFINE_INLINE
#endif//GUARD_FILE_H
> cat file.cc
#undef EFINE_INLINE
#include "file.h"
double dot(const double x[], const double y[], int n) {
double t = 0.0;
for (int j = 0; j < n; ++j)
t += x[j]*y[j];
return t;
}
> cat main.cc
#include "file.h"
int main (int argc, char* argv[]) {
// code to invoke dot
return 0;
}
> g++ -Wall -ansi -pedantic -c file.cc
Now, for all of your development, testing and debugging, you invoke
> g++ -Wall -ansi -pedantic -o main main.cc file.o
This compiles and links quickly but may run slowly.
Then, just before you are ready to release and distribute your code,
you invoke
> g++ -Wall -ansi -pedantic -DEFINE_INLINE -O2 -o main main.cc
This may take much longer to compile
but the optimized inline'd code may run much faster.
- Next message: Ron Natalie: "Re: why .hpp?"
- Previous message: E. Robert Tisdale: "Re: const in headers"
- In reply to: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Next in thread: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Reply: Kelly Mandrake: "Re: confusion with copy constructor and operator overloading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|