PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > inline functions in a c++ class
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
inline functions in a c++ class

Réponse
 
LinkBack Outils de la discussion
Vieux 24/02/2008, 17h51   #1
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut inline functions in a c++ class

Hi Everyone,

I had this doubt for quite some while, does defining a member
function within the class declaration makes it inline by default?
Would the compiler attempt to inline all calls to such member
functions?

class sample
{
public: void print()
{
cout<<"sample::print function invoked";
}
};

int main()
{
sample obj;
obj.print();
return(0);
}

Thanks in advance!!!

  Réponse avec citation
Vieux 24/02/2008, 17h58   #2
Rolf Magnus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inline functions in a c++ class

Rahul wrote:

> Hi Everyone,
>
> I had this doubt for quite some while, does defining a member
> function within the class declaration makes it inline by default?


Yes, if you mean that it has the same efffect as using the inline keyword on
the function.

> Would the compiler attempt to inline all calls to such member
> functions?


It might do that, or not. The only guaranteed effect of the inline keyword
in C++ is that there can be multiple definitions of the function in
different translation units, even if that function has external linkage.
Regarding optimization, the inline keyword is just a hint to the compilier
that some compilers simply ignore, deciding on their own when to inline a
function call and when not to.

  Réponse avec citation
Vieux 24/02/2008, 19h08   #3
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inline functions in a c++ class

>
> It might do that, or not. The only guaranteed effect of the inline keyword
> in C++ is that there can be multiple definitions of the function in
> different translation units, even if that function has external linkage.


I didn't know that... do you have any links for further info on this
one?
  Réponse avec citation
Vieux 25/02/2008, 04h12   #4
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inline functions in a c++ class

Rahul wrote:
>> It might do that, or not. The only guaranteed effect of the inline keyword
>> in C++ is that there can be multiple definitions of the function in
>> different translation units, even if that function has external linkage.

>
> I didn't know that... do you have any links for further info on this
> one?


The standard?

--
Ian Collins.
  Réponse avec citation
Vieux 25/02/2008, 18h26   #5
Andrey Tarasevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inline functions in a c++ class

Rahul wrote:
> I had this doubt for quite some while, does defining a member
> function within the class declaration makes it inline by default?


Yes, it does.

> Would the compiler attempt to inline all calls to such member
> functions?


It depends on many factors and in reality virtually all of them are
implementation-dependent. It might inline all calls, some of the calls,
or none of the calls. The decision to inline can really be made on
per-call basis.

Moreover, the compiler might inline calls to the functions that are not
explicitly declared 'inline' at its own discretion. For this reason, the
relationship between the 'inline' specifier and the actual inlining of
the calls might be (and is) significantly more loose then it is often
assumed to be. As other already noted, the only thing the 'inline'
specifier is guaranteed to do is to allow multiple definitions of the
same function with external linkage in the program.

--
Best regards,
Andrey Tarasevich
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10092 seconds with 13 queries