“无法将函数定义与现有声明匹配”,当包装在 std::vector 中时

“unable to match function definition to an existing declaration” when wrapped in std::vector

本文关键字:包装 std 中时 vector 函数 定义 声明      更新时间:2023-10-16

为什么这不起作用?我试过在那里扔一个额外的类型名,但无济于事。

    class binary_reader
    {
    public:
        template <typename Type>
        Type read();
    };
    template <typename Type>
    std::vector<Type> binary_reader::read()
    {
        ...
    }

在类声明中,使用 Type 作为返回值,但在方法实现中,使用 std::vector<Type> 作为返回值。

更改类声明或实现,它将起作用。