Giving a function implementation more than one name in c++

后端 未结 6 1642
走了就别回头了
走了就别回头了 2021-01-19 03:29

Let say I have a basic 2D vector class something like

class vector2
{
  int x, y;
}

these two values could be used to represent a position

6条回答
  •  深忆病人
    2021-01-19 04:17

    Your referenced link is AFAIK not a C feature either, but something specific to that particular compiler.

    C++ provides such a mechanism: it happens to be inlined functions! Worrying about the compiler not optimizing away the redundant call in an inlineable function is definitely premature optimization. Inline, then measure if you're worried about performance.

    If you're absolutely insisting on eliminating the merest chance of a redundant call, you might do something with preprocessor #defines... but beware: macros do not respect class boundaries, and your header files will sooner or later stomp on some other, unrelated code. Better not go there.

提交回复
热议问题