Visibility of template specialization of C++ function

前端 未结 9 694
情书的邮戳
情书的邮戳 2021-01-01 11:21

Suppose I have fileA.h which declares a class classA with template function SomeFunc(). This function is implemented directly

9条回答
  •  伪装坚强ぢ
    2021-01-01 12:02

    In Microsoft C++, I did an experiment with inline functions. I wanted to know what would happen if I defined incompatible versions of a function in different sources. I got different results depending on whether I was using a Debug build or a Release build. In Debug, the compiler refuses to inline anything, and the linker was linking the same version of the function no matter what was in scope in the source. In Release, the compiler inlined whichever version had been defined at the time, and you got differing versions of the function.

    In neither case were there any warnings. I kind of suspected this, which is why I did the experiment.

    I assume that template functions would behave the same, as would other compilers.

提交回复
热议问题