C++ 专门化stl容器的成员函数

C++ 专门化stl容器的成员函数,c++,templates,stl,template-specialization,C++,Templates,Stl,Template Specialization,我有一门课是这样的: class Foo { ... template<template<typename...> class container> void fillContainer(container<int> &out) { //add some numbers to the container } ... } class-Foo { ... 模板 空填充容器(容器和出) {

我有一门课是这样的:

class Foo
{

    ...
    template<template<typename...> class container>
    void fillContainer(container<int> &out)
    {
        //add some numbers to the container
    }
    ...

}
class-Foo
{
...
模板
空填充容器(容器和出)
{
//在容器中添加一些数字
}
...
}
我这样做是为了能够处理不同的stl容器。现在我想为std::vector创建一个专门化来保留内存(我知道要插入的数字量)。我阅读并发布,所以我做了以下工作:

class Foo
{
    //Same Thing as above
}

template<>
void Foo::fillContainer(std::vector<int> &out)
{
    //add some numbers to the container
}
class-Foo
{
//同上
}
模板
void Foo::fillContainer(std::vector&out)
{
//在容器中添加一些数字
}
现在我得到了错误:
错误:没有在'Foo'中声明成员函数'fillContainer'。
。我想问题是
模板


是否有可能将此函数专门化为
std::vector

没有理由尝试专门化它,只需添加一个重载:

class Foo
{
    ...
    template<template<typename...> class container>
    void fillContainer(container<int>& out)
    {
        //add some numbers to the container
    }

    void fillContainer(std::vector<int>& out)
    {
        //add some numbers to the container
    }

    ...
};
class-Foo
{
...
模板
空填充容器(容器和出)
{
//在容器中添加一些数字
}
空填充容器(标准::矢量和输出)
{
//在容器中添加一些数字
}
...
};

(在一些模糊的情况下,它会产生影响,例如,如果有人想要获取函数模板版本的地址,但没有什么需要对其进行专门化,而不是采用更简单的重载方法。)

没有理由尝试对其进行专门化,只需添加一个重载:

class Foo
{
    ...
    template<template<typename...> class container>
    void fillContainer(container<int>& out)
    {
        //add some numbers to the container
    }

    void fillContainer(std::vector<int>& out)
    {
        //add some numbers to the container
    }

    ...
};
class-Foo
{
...
模板
空填充容器(容器和出)
{
//在容器中添加一些数字
}
空填充容器(标准::矢量和输出)
{
//在容器中添加一些数字
}
...
};

(有一些模糊的情况下,它会产生不同,例如,如果有人想要获取函数模板版本的地址,但没有什么需要专门化的,而不是更简单的重载方法。)

为什么不为
vector
重载它?为什么不为
vector
重载它?