Google Groups Home
Help | Sign in
Use Inline in class?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 47 - Collapse all   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Immortal Nephi  
View profile
 More options Jul 5, 8:31 pm
Newsgroups: comp.lang.c++
From: Immortal Nephi <Immortal_Ne...@satx.rr.com>
Date: Sat, 5 Jul 2008 17:31:10 -0700 (PDT)
Local: Sat, Jul 5 2008 8:31 pm
Subject: Use Inline in class?
I want to know if the practice is the best.  Do I need to place inline
keyword inside class definition or outside member function
definition.  For example

class A
{
public:
     A();
     ~A();

     inline void Test(); // should place inline here?

};

inline void A::Test() // should place inline here?
{
{

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
HL  
View profile
 More options Jul 5, 8:54 pm
Newsgroups: comp.lang.c++
From: HL <moogle.l...@gmail.com>
Date: Sat, 5 Jul 2008 17:54:49 -0700 (PDT)
Local: Sat, Jul 5 2008 8:54 pm
Subject: Re: Use Inline in class?
On 7月6日, 上午8时31分, Immortal Nephi <Immortal_Ne...@satx.rr.com> wrote:

yes, you need.

another way is to define func in class.
class A{
public:
    void Test(){...};

};

Test is refered as inline.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile
 More options Jul 5, 9:00 pm
Newsgroups: comp.lang.c++
From: Sam <s...@email-scan.com>
Date: Sat, 05 Jul 2008 20:00:27 -0500
Local: Sat, Jul 5 2008 9:00 pm
Subject: Re: Use Inline in class?

Immortal Nephi writes:
> I want to know if the practice is the best.  Do I need to place inline
> keyword inside class definition or outside member function
> definition.  For example

> class A
> {
> public:
>      A();
>      ~A();

>      inline void Test(); // should place inline here?

No.

> };

> inline void A::Test() // should place inline here?

Yes.

  application_pgp-signature_part
< 1K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey Tarasevich  
View profile
 More options Jul 6, 4:00 am
Newsgroups: comp.lang.c++
From: Andrey Tarasevich <andreytarasev...@hotmail.com>
Date: Sun, 06 Jul 2008 01:00:09 -0700
Local: Sun, Jul 6 2008 4:00 am
Subject: Re: Use Inline in class?

If you want to define your inline member function outside the class
definition (as in your example above), you only need to specify 'inline'
in the member definition (the second 'inline' in your example)

   class A {
     ...
     void Test();
     ...
   };

   inline void A::Test()
   {
   }

--
Best regards,
Andrey Tarasevich


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juha Nieminen  
View profile
 More options Jul 6, 4:30 am
Newsgroups: comp.lang.c++
From: Juha Nieminen <nos...@thanks.invalid>
Date: Sun, 06 Jul 2008 08:30:31 GMT
Local: Sun, Jul 6 2008 4:30 am
Subject: Re: Use Inline in class?

Andrey Tarasevich wrote:
> If you want to define your inline member function outside the class
> definition (as in your example above), you only need to specify 'inline'
> in the member definition (the second 'inline' in your example)

  If this is the case, why is the keyword 'inline' even supported inside
class definitions? Isn't it completely obsolete and a no-op there?
(Basically there's not even one single case where specifying that
keyword in the class definition makes a difference.)

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Kanze  
View profile
 More options Jul 6, 6:16 am
Newsgroups: comp.lang.c++
From: James Kanze <james.ka...@gmail.com>
Date: Sun, 6 Jul 2008 03:16:08 -0700 (PDT)
Local: Sun, Jul 6 2008 6:16 am
Subject: Re: Use Inline in class?
On Jul 6, 10:30 am, Juha Nieminen <nos...@thanks.invalid> wrote:

> Andrey Tarasevich wrote:
> > If you want to define your inline member function outside
> > the class definition (as in your example above), you only
> > need to specify 'inline' in the member definition (the
> > second 'inline' in your example)
> If this is the case, why is the keyword 'inline' even
> supported inside class definitions? Isn't it completely
> obsolete and a no-op there?  (Basically there's not even one
> single case where specifying that keyword in the class
> definition makes a difference.)

You can specify inline on either the definition or any
declaration which precedes it, and the function will be inline.
Current practice is to specify it on the definition, but at
least one earlier compiler I used required it to be specified on
the first declaration that appeared.

Of course, current best pratice is not to use inline at all, so
the problem doesn't occur.

--
James Kanze (GABI Software)             email:james.ka...@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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joseph cook  
View profile
 More options Jul 6, 11:20 am
Newsgroups: comp.lang.c++
From: joseph cook <joec...@gmail.com>
Date: Sun, 6 Jul 2008 08:20:59 -0700 (PDT)
Local: Sun, Jul 6 2008 11:20 am
Subject: Re: Use Inline in class?

> Of course, current best practice is not to use inline at all, so
> the problem doesn't occur.

Why do you say this?   In-lining functions in a header file can be
critical for performance reasons.
Thanks,
Joe Cook

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Kanze  
View profile
 More options Jul 6, 11:37 am
Newsgroups: comp.lang.c++
From: James Kanze <james.ka...@gmail.com>
Date: Sun, 6 Jul 2008 08:37:43 -0700 (PDT)
Local: Sun, Jul 6 2008 11:37 am
Subject: Re: Use Inline in class?
On Jul 6, 5:20 pm, joseph  cook <joec...@gmail.com> wrote:

> > Of course, current best practice is not to use inline at all, so
> > the problem doesn't occur.
> Why do you say this?

Because it increases coupling.

> In-lining functions in a header file can be critical for
> performance reasons.

Really?  I never use it, and I've not had any performance
problems.

If you do actually have a performance problem, and the profiler
shows that it is in a tight loop where you do call a non-inlined
function, then inlining it is a simple and cheap optimization.
Using inline before the profiler says you have to, however, is
premature optimization.

--
James Kanze (GABI Software)             email:james.ka...@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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alf P. Steinbach  
View profile
 More options Jul 6, 11:59 am
Newsgroups: comp.lang.c++
From: "Alf P. Steinbach" <al...@start.no>
Date: Sun, 06 Jul 2008 17:59:13 +0200
Local: Sun, Jul 6 2008 11:59 am
Subject: Re: Use Inline in class?
* James Kanze:

Inlining things in headers is a technique that saves programmer's time both for
initial development, for use of the header, and for maintainance (which
reportedly constitutes about 80% of all programming work).

I agree that doing inlining for reasons of performance would be premature
optimization, of the kind that might even influence runtime in a negative way,
and bring in unwanted coupling and have other undesirable effect.

However, used as a means for programmer productivity, not as premature
optimization, its effect on coupling is generally negligible. It can even reduce
the number of files that must be opened and read during a build. I think the
programmer who's afraid of using std::vector just because it's perceived as a
large header & requires full def of element type, is seriously misguided.

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gennaro Prota  
View profile
 More options Jul 6, 1:25 pm
Newsgroups: comp.lang.c++
From: Gennaro Prota <inva...@yahoo.com>
Date: Sun, 06 Jul 2008 19:25:51 +0200
Local: Sun, Jul 6 2008 1:25 pm
Subject: Re: Use Inline in class?

Alf P. Steinbach wrote:
> * James Kanze:
 > [...]
>> If you do actually have a performance problem, and the profiler
>> shows that it is in a tight loop where you do call a non-inlined
>> function, then inlining it is a simple and cheap optimization.
>> Using inline before the profiler says you have to, however, is
>> premature optimization.

> Inlining things in headers is a technique that saves programmer's time
> both for initial development, for use of the header, and for
> maintainance (which reportedly constitutes about 80% of all programming
> work).

I think that if this is really your issue (hardly, but I'll assume you
have some measurements) then you (or your users in the case e.g. of
libraries, for which I've often heard the "header-only is easier"
claim) are likely to work with a severely limited environment and
toolset. To me, creating one more file is just a matter of issuing ":e
filename" and the file contents get initialized automatically with all
that can be written automatically. Similarly for building. As to
maintenance I really don't understand: what time do you save?

--
   Gennaro Prota  |  <https://sourceforge.net/projects/breeze/>
     Do you need expertise in C++?   I'm available.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alf P. Steinbach  
View profile
 More options Jul 6, 3:59 pm
Newsgroups: comp.lang.c++
From: "Alf P. Steinbach" <al...@start.no>
Date: Sun, 06 Jul 2008 21:59:48 +0200
Local: Sun, Jul 6 2008 3:59 pm
Subject: Re: Use Inline in class?
* Gennaro Prota:

It's also easy to write Perl. ;-)

> As to maintenance I
> really don't understand: what time do you save?

For things that are defined in the header file you only need to look at one
file, affecting continuity, and you see the relevant definition in context.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Kanze  
View profile
 More options Jul 7, 4:05 am
Newsgroups: comp.lang.c++
From: James Kanze <james.ka...@gmail.com>
Date: Mon, 7 Jul 2008 01:05:48 -0700 (PDT)
Local: Mon, Jul 7 2008 4:05 am
Subject: Re: Use Inline in class?
On Jul 6, 5:59 pm, "Alf P. Steinbach" <al...@start.no> wrote:

I don't know where you get that from.  It is a nightmare with
regards to maintenance, easily doubling the effort required.
(To begin with, if you don't know if the function is inlined or
not, you don't even know in which file to look for it.  And of
course, if you have to modify it, then all of the client code
needs to be recompiled.)

> I agree that doing inlining for reasons of performance would
> be premature optimization, of the kind that might even
> influence runtime in a negative way, and bring in unwanted
> coupling and have other undesirable effect.
> However, used as a means for programmer productivity, not as
> premature optimization, its effect on coupling is generally
> negligible.

If it's used in a template, it's negligible, because the
template code has to be included anyway (at least with most
current compilers).  If it's not a template, however, the effect
in practice can be quite high.

Obviously, it's only one factor: you can write impossible to
maintain code without a single inline function, and carefully
used, you can minimize the impact.  But globally, all of the
coding guidelines I've seen for application code forbid inline
functions---and usually also require user defined
implementations of the functions the compiler will generate by
default as well, since the compiler generated versions are
inline.  (The rules for library code are somewhat different,
since you often have to guess where the client code's
bottlenecks might occur.)

> It can even reduce the number of files that must be opened and
> read during a build. I think the programmer who's afraid of
> using std::vector just because it's perceived as a large
> header & requires full def of element type, is seriously
> misguided.

That, certainly.  But std::vector is (hopefully) stable code,
which isn't evolving while you're working.  So you won't end up
having to recompile everything because there was a small
correction in the implementation somewhere.  (If you upgrade
your comp