Templates and separate compilation

前端 未结 2 1126
梦谈多话
梦谈多话 2021-01-06 02:39

I want to write a program in C++ with separate compilation and I wrote this:

main.cpp

#include 
#include \"Stack.h\"
using namespace          


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 03:13

    Template classes need to have the method definitions inside the header file.

    Move the code you have in the .cpp file inside the header, or create a file called .impl or .imp, move the code there, and include it in the header.

    The compiler needs to know the method definitions to generate code for all specializations.

    Before you ask, no, there is no way to keep the implementation outside the header.

提交回复
热议问题