本文介绍了如何区分操作符++的前缀和后缀形式之间(当重载时)? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我为迭代器类重载了运算符++
Because I've overloaded the operator++
for an iterator class
template<typename T>
typename list<T>::iterator& list<T>::iterator::operator++()
{
//stuff
}
$ b b
但是当我尝试做
But when I try to do
list<int>::iterator IT;
IT++;
我收到有关没有postifx的警告 ++
,使用前缀形式。我如何具体重载前缀/ postifx形式?
I get a warning about there being no postifx ++
, using prefix form. How can I specifically overload the prefix/postifx forms?
推荐答案
编写相同的操作符重载的版本, int
类型。
Write a version of the same operator overload, but give it a parameter of type int
. You don't have to do anything with that parameter's value.
如果您有兴趣了解一下此语法是如何传递的,请访问。
If you're interested in some history of how this syntax was arrived out, there's a snippet of it here.
这篇关于如何区分操作符++的前缀和后缀形式之间(当重载时)? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!