Do functions defined inside a class need inline keyword ?

G

ganesh.gella

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
 
S

Stephen Howe

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

... or are these functions considered for inline by default as
the definition is provided as part of the class ?

Yes. You got it right.

Stephen Howe
 
E

Einar Forselv

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 ?

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

Jaspreet

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

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
the definition is provided as part of the class ?

You are correct.
 
U

upashu2

need to declare them as inline because functions defined inside a 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.
Yes.
 
J

Jaspreet

upashu2 said:
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.

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

:(
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top