| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Hicham Mouline" |
| Date: |
31 Jan 2008 06:32:20 AM |
| Object: |
in-class function definitions, inline |
hi,
I include a header file from 2 translation units. In this header file , I
have a "policy" class with only static member functions:
class C {
static double f1() { return 6.0; }
static bool f2() { return true; }
};
I would like to hint to the compiler to inline these functions.
I think i have read somewhere that functions defined in-class are
automatically hinted as inline... And i don't need to add the "inline"
keyword, and that i should add inline when the functions are defined
out-of-class, as:
class C {
static double f1();
static bool f2();
};
inline double C::f1()
{
return 6.0;
}
inline double C::f2()
{
return true;
}
regards,
.
|
|
| User: "Alf P. Steinbach" |
|
| Title: Re: in-class function definitions, inline |
31 Jan 2008 06:58:17 AM |
|
|
* Hicham Mouline:
hi,
I include a header file from 2 translation units. In this header file , I
have a "policy" class with only static member functions:
class C {
static double f1() { return 6.0; }
static bool f2() { return true; }
};
I would like to hint to the compiler to inline these functions.
I think i have read somewhere that functions defined in-class are
automatically hinted as inline...
Not exactly. When they're defined in-class they are defined inline.
And the effect is as if you had used the keyword "inline", which permits
equivalent definitions in other translation units, i.e., from a
practical point of view, permits the definitions to be in a header file.
The hinting about inline code generation comes on top of that, it's an
/additional/ but not very important effect of keyword "inline".
And i don't need to add the "inline"
keyword, and that i should add inline when the functions are defined
out-of-class, as:
class C {
static double f1();
static bool f2();
};
inline double C::f1()
{
return 6.0;
}
inline double C::f2()
{
return true;
}
If this is code in a header file, yes.
Cheers & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
|
|
|
|

|
Related Articles |
|
|