c++ - Defining member functions inside the class' definition -


i've wondered why codes , tutorial i've read declare member functions inside class , define outside this.

       class a{               dosomething();         };         a::dosomething(){              //doing          } 

instead of doing

       class a{               dosomething(){                   //doing                }          }; 

anyway, revising prof's course , found this:

"toute fonction membre définie dans sa classe (dans la déclaration de la classe) est considérée par le compilateur comme une fonction inline. le mot clé inline n'est plus utilisé."

which translates into;

"all member functions defined in class (in class' declaration) considered compiler inline function. keyword 'inline' no longer used"

what understand abut inline functions work macros. compiler copies entire block of code every instance function called.

my question is; statement in prof's course correct , if yes, reason behind it?

your professor's statement correct, understanding of inline means not. inline function allows multiple definitions across translation units, , doesn't mean call inlined (i.e. expanded macro).

if define free function in header without inline or static , include header in multiple translation units, you'll break 1 definition rule.

member functions similar, unless marked inline (which implicitly inside class definition).


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -