in-class function definitions, inline

H

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... 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,
 
A

Alf P. Steinbach

* 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top