What does it mean is deppending on compiller. In many cases the compiller just ignore the specification inline, for example when the function is recursive. John Fill
The keyword inline lets the compiler know that it need not create separate stack space for the function. Instead whenever the compiler finds the function-call, it will replace it with the function body directly thus making the function-call faster (so, for functions whose bodies are maybe a line or two - i would use the inline keyword). The keyword virtual simply means that you can implement the same function in another class, which inherits from this class, with a different implementation (polymorphism). So, you can have inline virtual functions, and I tend to write them as shown in the following example:
class A
{
private:
int a;
public:
virtual int getVal();
};
inline int A::getVal() { return a; }
another example would be:
class A
{
private:
int a;
public:
virtual int getVal() { return a; }
};
In the second example, the getVal() function is by default an inline function, since it has been declared and defined in the class declaration, so there is no need for the keyword inline - I'm not very sure about this statement, but this is what I think happens, so I would like to be corrected if I'm wrong.
I am not sure either Andyrau, and probably shouldn't comment based on my myopic view. JohnFill is correct in that it depends on the compiler. Microsoft's compiler (when using the release build) makes a determination on whether or not to make a function inline. Based on optimization beyond my scope, a function that is declared inline may not actually be inline and a function not declared inline may be inline. I agree with Andyrau that small often recurring functions declared inline do improve performance. I would also suggest that if performance is a real issue and you are using Visual Studio, that you use the Profile option which will tell you where the program spends a majority of its time and focus you on the areas where optimization will give you the biggest yield.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.