gpt4 book ai didi

c++ - QVector 和 std::vector 的大小方法

转载 作者:太空狗 更新时间:2023-10-29 20:27:33 25 4
gpt4 key购买 nike

QVector的size方法是int类型,但是std::vector中的size方法是unsigned。为什么不一样。无符号类型不是保存大小的正确方法吗,因为它不能为负数?

最佳答案

因为 they discussed it in 1999得出的结论是 int 是更好的选择,因为返回 uint 的函数数量相对较少,并且他们对警告感到不满:

Subject: Re: killing uint as return type in Qt.
From: Alex Sandro Queiroz e Silva <asandro@xxxxxxxxxxxxx>
Date: Wed, 17 Mar 1999 15:29:37 -0300 (EST)
Cc: qt-interest@xxxxxxxx
To: Arnt Gulbrandsen <arnt@xxxxxxxx>

On 17 Mar 1999, Arnt Gulbrandsen wrote:

About 0.15% of the functions in Qt return uint. Most of those are called QMumble::size() or QMumble::count(). These functions never need to return a negative number, so really, uint is the right type for them to return.

But it's a nuisance, to me at least. I keep comparing them with ints, putting them in variables that -can- contain negative numbers, and so on. I've written

 if ( blah->count() < i )

and gotten compiler warning too many times already.

So I am considering changing the return type for these functions to int in Qt 2.0. What do you think? You're the users - do you want correctness and total backward compatibility or would you prefer more convenience?

--Arnt

我觉得这次方便比较好,我们现在都是那种 我们可能会从这个方法中得到结果,所以......

-- 亚历克斯 asandro@lcg.dc.ufc.br

关于c++ - QVector 和 std::vector 的大小方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16088815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com