(Inline) The reason why inline functions cannot be virtual functions (virtual)

Source: Internet
Author: User

1. inline functions are static actions, while virtual functions are dynamic actions, which are in conflict.
2. We can see some virtual functions like inline functions, because whether a function is an inline function is determined by the compiler rather than the calculation. We can only advise the compiler that a function can be an inline function (Inline keyword), but the compiler has its own judgment rules. Therefore, this situation may occur:
2.1 The functions we declare with Inline do not have inline
2.2 The inline function we didn't declare with Inline is inline.
2.3 For inline functions, the compiler still compiles them into an address-specific function
Therefore, the situation is complicated. From the perspective of high-level, it is difficult to judge whether the function is inline. From the perspective of low-level, it is clear that non-inline functions follow the function call mechanism, call is used in the assembly. Inline functions do not have these.

The Inline Function indicates that the function is internal, and it recommends that the function compute directly expand the function compute where the function is used.
Insert the caller's proxy. This is just a indication that the caller will not be inlined or the root cause will be identified as inline.
The internal structure of the function data, such as: whether to include the cycle, whether to use the function data, and so on.
1. There is no doubt that the number of response letters will not be compromised, because only the runtime of the response letter can be identified.
It is not a problem to use the plug-in for future use, while the inner phase will expand and install this bright line.
2. There are two inline table modes. One is to use inline in the actual file (. cpp) to indicate that this is regarded as internal display, and the other is
As you said, the classification and definition are put into the same file, which is regarded as an internal component, but as mentioned above, inline is just
The prompt indicates whether the program will be inactive or not.

 

 

# Include <iostream>
Using namespace STD;
Class
{
Public:
 
Inline virtual void virfun () // The member function of the class is implemented as the callback function in static mode.
{
Cout <"I Am a virtual function in a, and inline does not work! "<Endl;
}
Void F ();

};
Inline void a: F ()
{
Cout <"I am a real inline function and cannot be set as a virtual function at the same time! "<Endl;
}
Class B: public
{
Public:
Virtual void virfun ()
{
Cout <"I'm a virtual function in B! "<Endl;
}
};
Int main ()
{
B;
B. virfun ();
A;
A. F ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.