Multiple-File Template Implementation

前端 未结 3 1939
迷失自我
迷失自我 2021-01-23 03:38

With normal functions, the declaration and definition are often separated across multiple files like so:

// Foo.h

namespace Foo
{
    void Bar();
}
3条回答
  •  無奈伤痛
    2021-01-23 04:24

    I'm disappointed that no answers mentioned that the C++ standard permits you to separate the definition from the declaration. It goes like this:

    // Foo.h
    export template T f();
    

     

    // Foo.cpp
    #include "Foo.h"
    
    export template T f()
    {
        // blah blah
    }
    

    Unfortunately, almost no compilers support export. Comeau is one that does.

    However, export is removed from C++ in C++0x.

提交回复
热议问题