相关疑难解决方法(0)

适用于STL容器的简单C++模板

我需要一个这样的模板,它可以很好地工作

template <typename container> void mySuperTempalte (const container myCont)
{
    //do something here
}
Run Code Online (Sandbox Code Playgroud)

那么我想专门为std :: string上面的模板,所以我想出了

template <typename container> void mySuperTempalte (const container<std::string> myCont)
{
    //check type of container
    //do something here
}
Run Code Online (Sandbox Code Playgroud)

哪个不起作用,并抛出一个错误.我想让第二个例子起作用然后如果可能我想在模板中添加一些代码以检查是否使用了std :: vector/std :: deque/std :: list,在每个中执行不同的操作案件.所以我使用了模板,因为99%的代码对于矢量和deques等都是相同的.

c++ containers templates stl

4
推荐指数
3
解决办法
7345
查看次数

标签 统计

c++ ×1

containers ×1

stl ×1

templates ×1