in-class function definitions, inline



 DEVELOP > c-Plus-Plus > in-class function definitions, inline

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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?
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER