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

Ways to make inline work?

P: n/a
Hi, group

First, I write same cases I've already known, I don't concern that
specific compiler really do inline or not.
Please check them if they are right, and add the cases I miss

1.
// a.h
inline void f() {}

*inline*

2.
//a.h
inline void f();
//a.cpp
#include "a.h"
void f() {}

*NOT* inline, compiler just ignores the keyword

3.
// a.h
class A {
void f1() {}
inline void f2() {}
};

*inline*

4.
// a.h
class A {
inline void f2();
};

//a.cpp
#include "a.h"

void A::f() {}

*not* inline
5.
// a.h
class A {
void f();
};

//a.cpp
#include "a.h"

inline
void A::f() {}

*not* inline

6.
// a.h
class A {
void f();
};

inline void A::f() {}

*inline*

7.
//a.h
template <typename T>
class A {
void f1();
void f2() {}
};

template <typename T>
void A::f1() {}

*inline*

After so many examples,
I sum up from my humble experience, *inline* works when coming with the
function definition not the declaration. Is there any exception?

Like
// a.h
class A {
inline void f();
};

void A::f() {}

*inline*

thanks
Aug 3 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Alf P. Steinbach wrote:
Additionally, when a member function is defined within a class
definition, it's implicitly "inline", so there the "inline" keyword is
superflous.

And that's it.
You forgot template functions: They are implicitly inline too.
Aug 3 '07 #2

P: n/a
On Aug 4, 12:39 am, Juha Nieminen <nos...@thanks.invalidwrote:
Alf P. Steinbach wrote:
Additionally, when a member function is defined within a class
definition, it's implicitly "inline", so there the "inline" keyword is
superflous.
And that's it.
You forgot template functions: They are implicitly inline too.
No they're not.

--
James Kanze (GABI Software) email:james.kanze:gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.