By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,917 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,917 IT Pros & Developers. It's quick & easy.

Do functions defined inside a class need inline keyword ?

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> 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
Jul 23 '05 #2

P: n/a
ga**********@gmail.com wrote:
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.
Jul 23 '05 #3

P: n/a
ga**********@gmail.com wrote:
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.

-Thanks
Ganesh


Jul 23 '05 #4

P: n/a
>> need to declare them as inline because functions defined inside a
class are considered inline if compiler can make them inline. 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.
are these functions considered for inline by default as
the definition is provided as part of the class ?

Yes.

Jul 23 '05 #5

P: n/a
upashu2 wrote:
need to declare them as inline because functions defined inside a
class are considered inline if compiler can make them inline.

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

:(

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.