Connecting Tech Pros Worldwide Forums | Help | Site Map

Do functions defined inside a class need inline keyword ?

ganesh.gella@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi All,

Wanted to make sure on this,

I have some functions for which I am providing the definition inside
the class definition. (As these are very small functions like get and
set).

Do i need to declare these functions as inline (I would like them to be
inlined) ? or are these functions considered for inline by default as
the definition is provided as part of the class ?

-Thanks
Ganesh


Stephen Howe
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Do functions defined inside a class need inline keyword ?


> I have some functions for which I am providing the definition inside[color=blue]
> the class definition. (As these are very small functions like get and
> set).
>
> Do i need to declare these functions as inline (I would like them to be
> inlined) ?[/color]

No.
[color=blue]
>... or are these functions considered for inline by default as
> the definition is provided as part of the class ?[/color]

Yes. You got it right.

Stephen Howe


Einar Forselv
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Do functions defined inside a class need inline keyword ?


ganesh.gella@gmail.com wrote:[color=blue]
> Hi All,
>
> Wanted to make sure on this,
>
> I have some functions for which I am providing the definition inside
> the class definition. (As these are very small functions like get and
> set).
>
> Do i need to declare these functions as inline (I would like them to be
> inlined) ? or are these functions considered for inline by default as
> the definition is provided as part of the class ?[/color]

As far as I remember a function defined inside your class definition
will be considered as an inline function.

class A {
public:
int getSomething() { [method definition] };
}

would be the same as :

class A {
public:
int getSomething();
}

inline int A::getSomething() {
[method definition]
}

Correct me if im wrong.
Jaspreet
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Do functions defined inside a class need inline keyword ?


ganesh.gella@gmail.com wrote:[color=blue]
> Hi All,
>
> Wanted to make sure on this,
>
> I have some functions for which I am providing the definition inside
> the class definition. (As these are very small functions like get and
> set).
>
> Do i need to declare these functions as inline (I would like them to be
> inlined) ?[/color]

No need to declare them as inline because functions defined inside a
class are considered inline if compiler can make them inline. It should
work in your case since you are using simple get and set functions.

or are these functions considered for inline by default as[color=blue]
> the definition is provided as part of the class ?[/color]

You are correct.
[color=blue]
>
> -Thanks
> Ganesh[/color]

upashu2
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Do functions defined inside a class need inline keyword ?


>> need to declare them as inline because functions defined inside a[color=blue][color=green]
>>class are considered inline if compiler can make them inline.[/color][/color]
The compiler treats the inline expansion options and keywords as
suggestions. There is no guarantee that functions will be inlined. You
cannot force the compiler to inline a particular function.

A class's member functions can be declared inline either by using the
inline keyword or by placing the function definition within the class
definition.
[color=blue][color=green]
>> are these functions considered for inline by default as
> >the definition is provided as part of the class ?[/color][/color]
Yes.

Jaspreet
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Do functions defined inside a class need inline keyword ?


upashu2 wrote:[color=blue][color=green][color=darkred]
> >> need to declare them as inline because functions defined inside a
> >>class are considered inline if compiler can make them inline.[/color][/color]
> The compiler treats the inline expansion options and keywords as
> suggestions. There is no guarantee that functions will be inlined. You
> cannot force the compiler to inline a particular function.
>
> A class's member functions can be declared inline either by using the
> inline keyword or by placing the function definition within the class
> definition.[/color]

Somehow the "No" word and the rest of the post went astray and there
was a gap of 2 lines in between which changed the whole meaning of my
post :(

Apologies for that. Please read my post with its first word as "No".

:(

Closed Thread