INSERTED FUNCTION MEMBERS

If the function is short so that its definition fit in a few lines, than it is possible to specify a definition into class declaration. Thus, we get inline definition of member function. Let’s rewrite our class vector in the way that function Multiplywithscalar() is inserted.
#include "stdafx.h"
#include "iostream"
using namespace std;
class Vector{
       float ax, ay;
       void Multiplywithscalar(float scalar){
             ax *= scalar;
             ay *= scalar;
       }
};

int _tmain(int argc, _TCHAR* argv[])
{
       return 0;
}

The reasons for which is useful to make member function inserted is the same as for usual functions. (link soon available).
IMPORTANT: Member function which is defined inside class declaration is always inserted without explicit use of keyword inline.
If it’s inconvenient to place inserted function inside class declaration the same effect can be accomplished using keyword inline like in the following example:
class Vector{
public:
       float ax, ay;
       inline void Multiplywithscalar(float scalar);
};
void Vector::Multiplywithscalar(float scalar){


}
Share on Google Plus