简体   繁体   中英

Size method of QVector and std::vector

The size method of QVector is of type int , but the same method in std::vector is unsigned . Why is the difference. Isn't unsigned type the right way to hold size, since it can't be negative?

Because they discussed it in 1999 and got to the conclusion that int is a better choice, since the number of functions returning uint was relatively small and they were displeased by the warnings:

 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

I think this time convenience is better, we all now the kind of results we may get from this methos, so...

-- Alex asandro@lcg.dc.ufc.br

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM