简体   繁体   中英

c++ inline function and pass by reference

Inline function simply copies the code to the main function, and a function that pass parameter by reference make parameter an alias for the original variable. My question is: for two functions with the same time complexity and other conditions, which one will process faster, make the function an inline function or pass the variable by reference?

I think you have a misconception about what inline does. It allows a function to be defined in multiple translation units and it is a hint to the compiler to consider inlining the function. A function might not be inlined even though it is declared inline , and a function not declared inline might, nevertheless, be inlined at link time.

Broad questions about performance are almost impossible to answer definitively. If you care about performance, I suggest benchmarking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM