Re: 64 bit C++ and OS defined types
* Christopher:
class MySpecialContainer
{
public:
const unsigned GetNumElements() const
The 'const' for the result type is superfluous and should be omitted.
The 'Get' in the name is superfluous and should be omitted (it may have some
purpose in Java but in C++ it's only noise, i.e. it has some negative impact for
readability etc. and adds nothing positive, so it's irrational to use it).
And even though the standard library has size methods with unsigned result type,
also that is an abomination. It's just sh*tty design, very much so, to use a C++
built-in type, where there's no guaranteed overflow checking, to indicate some
limited value range (technically: (1) it has no advantages, and (2) it has lots
of problems, including very serious ones, so (3) it's just sh*tty). Instead use
a signed type such as 'int' or 'long' or, if you absolutely must, 'ptrdiff_t'.
{
return m_udts.size();
}
private:
unsigned m_numElements;
typedef std::vector<UDT> UDTVec;
UDTVec m_udts;
}
Now the return value of size() is 64 bits and does not convert to an
unsigned.
It should convert.
If not then your compiler is very non-standard.
However, you should not use 'unsigned' here (see above).
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!