Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi, I want to know if there is a 2

Status
Not open for further replies.

ila

Programmer
Apr 3, 2001
9
FR
hi,

I want to know if there is anything
called inline-virtual function..
and what does it mean??

Thanks
Lak
 
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.

Andyrau
 
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.

HTH,
JC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top