F
Frederick Gotham
The original purpose of "inline" was that code could be "expanded in
place". Of course, it has other uses...
For one thing, the following two translation units will compile together
succesfully into a program:
/* source1.cpp */
inline int Func(double arg)
{
static double d = 0.;
return d += arg;
}
int main()
{
Func( 24.333);
}
/* source2.cpp */
inline int Func(double arg)
{
static double d = 0.;
return d += arg;
}
Here, "inline" alleviates our need to abide by the "One Definition Rule".
I have two questions though:
(1) What would be the effect of putting "extern" or "static" before
an inline function? Do inline functions have internal linkage, external
linkage, or neither?
(2) Template functions too seem to alleviate our need to abide by the
"One Definition Rule". Is this true? What would be the effect of putting
"inline", "extern" or "static" before a template function?
place". Of course, it has other uses...
For one thing, the following two translation units will compile together
succesfully into a program:
/* source1.cpp */
inline int Func(double arg)
{
static double d = 0.;
return d += arg;
}
int main()
{
Func( 24.333);
}
/* source2.cpp */
inline int Func(double arg)
{
static double d = 0.;
return d += arg;
}
Here, "inline" alleviates our need to abide by the "One Definition Rule".
I have two questions though:
(1) What would be the effect of putting "extern" or "static" before
an inline function? Do inline functions have internal linkage, external
linkage, or neither?
(2) Template functions too seem to alleviate our need to abide by the
"One Definition Rule". Is this true? What would be the effect of putting
"inline", "extern" or "static" before a template function?