Splitting templated C++ classes into .hpp/.cpp files--is it possible?

前端 未结 16 863
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 17:27

I am getting errors trying to compile a C++ template class which is split between a .hpp and .cpp file:

$ g++ -c -o main.o main.cpp         


        
16条回答
  •  伪装坚强ぢ
    2020-11-22 17:54

    Only if you #include "stack.cpp at the end of stack.hpp. I'd only recommend this approach if the implementation is relatively large, and if you rename the .cpp file to another extension, as to differentiate it from regular code.

提交回复
热议问题