473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Do functions defined inside a class need inline keyword ?

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
5 1910
> 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
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
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
>> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
13
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg....
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
3
by: Ruben Campos | last post by:
I've found a problem with types defined inside a template. With a non-template class, I can write the following: // MyClass.hpp class MyClass { // ... typedef unsigned int MyType; MyType...
3
by: Dave | last post by:
Hello all, Please consider this code: #ifndef FOO_INCLUDED #define FOO_INCLUDED // File: foo.h class foo {
4
by: John Goche | last post by:
Hello, I have been going through several header source files which define classes with inline functions. In the case where the inline functions are not defined in place, the inline functions...
2
by: DaTurk | last post by:
Hi, I have an interesting issue, well, it's not really an issue, but I'd like to understand the mechanics of what's going on. I have a file, in CLI, which has a class declared, and a static...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.