Circular Inclusion with Templates

后端 未结 2 1868
长发绾君心
长发绾君心 2020-12-30 18:19

The following code compiles perfectly:

// MyFile.h

#ifndef MYFILE_H_INCLUDED
#define MYFILE_H_INCLUDED

template 
class MyClass
{
          


        
2条回答
  •  清酒与你
    2020-12-30 18:46

    • Rename the file "MyFile.cpp" to "MyFile.tpp".
    • Remove the include guards from "MyFile.tpp"
    • Change the include in "MyFile.h" so it is "MyFile.tpp"
    • Remove the the include inside "MyFile.tpp"

    Note: Because the file is a *.tpp file (not *.cpp) it should not be included by other build system operations. If you have added it manually remove it.

    Make sure the only place that includes .tpp is the last line in .h

提交回复
热议问题