【发布时间】:2015-06-29 23:26:32
【问题描述】:
编译器无法区分两种不同类型的迭代器。
在这里查看这两种类型。
typedef std::set<int, std::greater<int> > PriceBookBuy;
typedef std::set<int, std::less<int> > PriceBookSell;
typedef PriceBookBuy::iterator PriceBookBuyIter;
typedef PriceBookSell::iterator PriceBookSellIter;
我想重载一个基于两种迭代器类型的模板方法。
class LVOrderBookBin
{
int a;
int b;
public:
template<typename PriceBookBuy>
void erasePriceLevel(std::vector<PriceBookBuyIter> remover) throw()
{
b++;
remover.begin();
}
template<typename PriceBookSell>
void erasePriceLevel(std::vector<PriceBookSellIter> remover) throw()
{
a++;
remover.begin();
}
};
典型用法:
int main()
{
std::vector< PriceBookBuyIter> vecBuy(3);
std::vector< PriceBookSellIter> vecSell(3);
LVOrderBookBin lv;
lv.erasePriceLevel<PriceBookBuy>(vecBuy);
lv.erasePriceLevel<PriceBookSell>(vecBuy);
}
与 Vs2008 一起使用的代码相同,但不能与 VS2013 一起编译。它也不能用 gcc 编译。
错误:'template void LVOrderBookBin::erasePriceLevel(std::vector, std::allocator >>)' 不能重载
有解决办法吗?
【问题讨论】:
-
请比“不起作用”更具体。
-
我的意思是它不能编译。错误:'template
void LVOrderBookBin::erasePriceLevel(std::vector<:_rb_tree_const_iterator>, std::allocator<:_rb_tree_const_iterator>> >)' 不能重载
标签: c++ templates visual-studio-2013 stl iterator