C++ template function compiles in header but not implementation

前端 未结 6 1696
梦谈多话
梦谈多话 2020-12-02 14:53

I\'m trying to learn templates and I\'ve run into this confounding error. I\'m declaring some functions in a header file and I want to make a separate implementation file w

6条回答
  •  时光说笑
    2020-12-02 15:16

    A template function is not real function. The compiler turns a template function into a real function when it encounters a use of that function. So the entire template declaration has to be in scope it finds the call to DumpVector, otherwise it can't generate the real function.
    Amazingly, a lot of C++ intro books get this wrong.

提交回复
热议问题