term does not evaluate to a function taking 1 arguments

Discussion in 'C++' started by KevinSimonson, Oct 23, 2010.

  1. 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". Now _it looks to
    me_ like the solution to this syntax is just to take out the empty
    pair of parentheses, change "return SwapEndianess< T >()( value );" to
    "return SwapEndianess< T >( value );". Can anyone see any problem
    with me doing that? If it doesn't compile, then I'll know right away,
    but I thought I'd better let the readers of this forum know I'm doing
    this in case they can see any logical errors that might result from me
    doing this. Any pointers will be greatly appreciated.

    Kevin S
    KevinSimonson, Oct 23, 2010
    #1
    1. Advertising

  2. KevinSimonson

    Luc Danton Guest

    On 23/10/2010 02:50, 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". Now _it looks to
    > me_ like the solution to this syntax is just to take out the empty
    > pair of parentheses, change "return SwapEndianess< T>()( value );" to
    > "return SwapEndianess< T>( value );". Can anyone see any problem
    > with me doing that? If it doesn't compile, then I'll know right away,
    > but I thought I'd better let the readers of this forum know I'm doing
    > this in case they can see any logical errors that might result from me
    > doing this. Any pointers will be greatly appreciated.
    >
    > Kevin S


    There is an extra set of parentheses because there is first a
    constructor call. The next set of parentheses if a call to operator().
    Now I am not familiar with this compiler error message but it is
    possible that swapEndianess was instantiated with a type not supported
    by SwapEndianess. Thus SwapEndianess<T>() indeed would not evaluate to a
    "function" (which I assume has to be understood as "function-like
    object") taking 1 argument because SwapEndianess only provides an
    operator() in specializations.

    Try removing the default template, i.e. only have:

    template<typename T>
    struct SwapEndianess;

    which is a forward decl. and not a class/struct definition. If the error
    message is something like 'use of an incomplete type' (you have to be
    familiar with your compiler I'm afraid) then that's the error.
    Alternatively you could put a static assertion in the default template
    body but I'm not sure how this works (last time I tried my compiler
    complained even when the template was not instantiated because the
    static assertion did not depend on the template params).

    Note that given some of your other threads posted for the same project,
    I suspect that you have a misconfiguration somewhere: some types like
    long or unsigned long seem to be different than what the original
    writers expected (hence SwapEndianess<T> picked a specialization for
    them, and they had implicit or no conversion at all to DWORD or whatever
    other typedefs). Check that perhaps the project expects to be compiled
    as 32bit if that maybe affects types on your toolchain.
    Luc Danton, Oct 23, 2010
    #2
    1. Advertising

  3. On Oct 22, 7:05 pm, Luc Danton <> wrote:
    > On 23/10/2010 02:50, KevinSimonson wrote:
    > > 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".  Now _it looks to
    > > me_ like the solution to this syntax is just to take out the empty
    > > pair of parentheses, change "return SwapEndianess<  T>()( value );" to
    > > "return SwapEndianess<  T>( value );".  Can anyone see any problem
    > > with me doing that?  If it doesn't compile, then I'll know right away,
    > > but I thought I'd better let the readers of this forum know I'm doing
    > > this in case they can see any logical errors that might result from me
    > > doing this.  Any pointers will be greatly appreciated.

    >
    > > Kevin S

    >
    > There is an extra set of parentheses because there is first a
    > constructor call. The next set of parentheses if a call to operator().
    > Now I am not familiar with this compiler error message but it is
    > possible that swapEndianess was instantiated with a type not supported
    > by SwapEndianess. Thus SwapEndianess<T>() indeed would not evaluate to a
    > "function" (which I assume has to be understood as "function-like
    > object") taking 1 argument because SwapEndianess only provides an
    > operator() in specializations.
    >
    > Try removing the default template, i.e. only have:
    >
    > template<typename T>
    > struct SwapEndianess;
    >
    > which is a forward decl. and not a class/struct definition. If the error
    > message is something like 'use of an incomplete type' (you have to be
    > familiar with your compiler I'm afraid) then that's the error.
    > Alternatively you could put a static assertion in the default template
    > body but I'm not sure how this works (last time I tried my compiler
    > complained even when the template was not instantiated because the
    > static assertion did not depend on the template params).
    >
    > Note that given some of your other threads posted for the same project,
    > I suspect that you have a misconfiguration somewhere: some types like
    > long or unsigned long seem to be different than what the original
    > writers expected (hence SwapEndianess<T> picked a specialization for
    > them, and they had implicit or no conversion at all to DWORD or whatever
    > other typedefs). Check that perhaps the project expects to be compiled
    > as 32bit if that maybe affects types on your toolchain.


    Okay, I removed the default template, so now it reads:

    template<typename T>
    struct SwapEndianess;

    and I put back the empty parenthesis where I took it out, so down
    below it reads:

    template<typename T>
    inline T swapEndianess(T value)
    {
    return SwapEndianess< T >()( value );
    }

    but then when I try to build it I still get an error message; this
    time it says:
    "1>c:\<path>\shareaza\hashlib\utility.hpp(221): error C2514:
    'SwapEndianess<T>' : class has no constructors". So do I need to put
    in a constructor? If so, I'm not sure how I'd write it. Would it be
    enough to just write:

    template<typename T>
    struct SwapEndianess;

    SwapEndianess ()
    {
    }

    Or how should I write it?

    Kevin S
    KevinSimonson, Oct 23, 2010
    #3
  4. KevinSimonson

    Luc Danton Guest

    On 23/10/2010 03:34, KevinSimonson wrote:
    > On Oct 22, 7:05 pm, Luc Danton<> wrote:
    >> > On 23/10/2010 02:50, KevinSimonson wrote:
    >>> > > 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". Now _it looks to
    >>> > > me_ like the solution to this syntax is just to take out the empty
    >>> > > pair of parentheses, change "return SwapEndianess< T>()( value );" to
    >>> > > "return SwapEndianess< T>( value );". Can anyone see any problem
    >>> > > with me doing that? If it doesn't compile, then I'll know right away,
    >>> > > but I thought I'd better let the readers of this forum know I'm doing
    >>> > > this in case they can see any logical errors that might result from me
    >>> > > doing this. Any pointers will be greatly appreciated.
    >> >
    >>> > > Kevin S
    >> >
    >> > There is an extra set of parentheses because there is first a
    >> > constructor call. The next set of parentheses if a call to operator().
    >> > Now I am not familiar with this compiler error message but it is
    >> > possible that swapEndianess was instantiated with a type not supported
    >> > by SwapEndianess. Thus SwapEndianess<T>() indeed would not evaluate to a
    >> > "function" (which I assume has to be understood as "function-like
    >> > object") taking 1 argument because SwapEndianess only provides an
    >> > operator() in specializations.
    >> >
    >> > Try removing the default template, i.e. only have:
    >> >
    >> > template<typename T>
    >> > struct SwapEndianess;
    >> >
    >> > which is a forward decl. and not a class/struct definition. If the error
    >> > message is something like 'use of an incomplete type' (you have to be
    >> > familiar with your compiler I'm afraid) then that's the error.
    >> > Alternatively you could put a static assertion in the default template
    >> > body but I'm not sure how this works (last time I tried my compiler
    >> > complained even when the template was not instantiated because the
    >> > static assertion did not depend on the template params).
    >> >
    >> > Note that given some of your other threads posted for the same project,
    >> > I suspect that you have a misconfiguration somewhere: some types like
    >> > long or unsigned long seem to be different than what the original
    >> > writers expected (hence SwapEndianess<T> picked a specialization for
    >> > them, and they had implicit or no conversion at all to DWORD or whatever
    >> > other typedefs). Check that perhaps the project expects to be compiled
    >> > as 32bit if that maybe affects types on your toolchain.

    > Okay, I removed the default template, so now it reads:
    >
    > template<typename T>
    > struct SwapEndianess;
    >
    > and I put back the empty parenthesis where I took it out, so down
    > below it reads:
    >
    > template<typename T>
    > inline T swapEndianess(T value)
    > {
    > return SwapEndianess< T>()( value );
    > }
    >
    > but then when I try to build it I still get an error message; this
    > time it says:
    > "1>c:\<path>\shareaza\hashlib\utility.hpp(221): error C2514:
    > 'SwapEndianess<T>' : class has no constructors". So do I need to put
    > in a constructor? If so, I'm not sure how I'd write it. Would it be
    > enough to just write:
    >
    > template<typename T>
    > struct SwapEndianess;
    >
    > SwapEndianess ()
    > {
    > }
    >
    > Or how should I write it?
    >
    > Kevin S


    No, I assume that this is the standard error message when trying to
    instantiate an incomplete type. My original message offered help on how
    to diagnose the error, not on how to fix it because it depends on what
    you want to do. I made you change the empty default template into an
    incomplete type so that we can now ascertain that we're trying
    swapEndianess is called with a type T that SwapEndianess is not
    specialized for. 'Fixing' this depends on what you want to do.

    Namely, if you want to compile the code 'as is' to build the binaries
    (i.e. you assume that there is no bug), I do not advise piling hack upon
    hacks to coerce your compiler. *If* the original source once compiled
    but doesn't now, I think you have configuration issues.
    Luc Danton, Oct 23, 2010
    #4
  5. KevinSimonson

    Ian Collins Guest

    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).

    --
    Ian Collins
    Ian Collins, Oct 23, 2010
    #5
  6. KevinSimonson

    Jorgen Grahn Guest

    On Sat, 2010-10-23, Ian Collins wrote:
    > On 10/23/10 01:50 PM, KevinSimonson wrote:

    ....
    >> struct SwapEndianess {};

    ....
    > There nothing wrong with the code, the compiler is probably trying to
    > tell you [...]


    Well, there are at least two problems:
    - unconditional swapping is a hint that there may be a design flaw
    in the code, or in the network protocol. I wouldn't be surprised if
    they're also doing non-portable casts (like taking an uint8_t* and casting
    it to uint32_t*).
    - they spell 'endianness' incorrectly :)

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Oct 23, 2010
    #6
  7. KevinSimonson

    Bo Persson Guest

    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
    Bo Persson, Oct 23, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kushalsoftpro
    Replies:
    6
    Views:
    2,170
    John Harrison
    Nov 4, 2004
  2. Abhi
    Replies:
    7
    Views:
    2,466
  3. Replies:
    2
    Views:
    330
    mlimber
    Dec 14, 2006
  4. Hicham Mouline
    Replies:
    7
    Views:
    346
    Hicham Mouline
    Jan 6, 2009
  5. Jim Cain
    Replies:
    1
    Views:
    194
    Yukihiro Matsumoto
    Jul 18, 2003
Loading...

Share This Page