为什么这个不是完整的模板专业化

why is this not full template specialization

本文关键字:专业化 为什么      更新时间:2023-10-16

我想在什么'通行证上专业地专业化一些功能,我想知道为什么这不编译?(这是一个课程的一部分):

    struct Passes {
        enum Value {
            First,
            Second
        };
    };
    template<Passes::Value Pass_t> void output();
    template<> void output<Passes::Second>();

建议?我使用英特尔编译器收到的错误是:

 error: an explicit template argument list is not allowed on this declaration

建议?

首先,发布错误消息。我认为您有一个与我的类似的(一旦我将代码片段扩展到我可以编译的东西):

explicit specialization in non-namespace scope

然后,阅读错误消息。正如它所说,您只能在命名空间范围中专业一个模板,而不是在课堂内:

struct Thing {
    // Primary template declared as a class member
    template<Passes::Value Pass_t> void output();
};
// Specialisation declared at namespace scope
template<> void Thing::output<Thing::Passes::Second>();