issue with the stl and operators

Discussion in 'C++' started by Sean Farrow, Aug 31, 2008.

  1. Sean Farrow

    Sean Farrow Guest

    Hi:
    When compiling the folowing code under visual c++ 2005 I get he following
    error:
    C3848: expression having type 'const BitSetComp' would lose some
    const-volatile qualifiers in order to call 'const bool BitSetComp::eek:perator
    ()(const KeyType &,const KeyType &)'
    This is in the file xtree on line 1174. The code causing this is:
    struct BitSetComp

    {

    bool const operator()(const KeyType& lhs, const KeyType& rhs)

    {

    return lhs.to_ulong() < rhs.to_ulong();

    }

    };

    Anyone got a clue what the issue is, and what's causing this?

    What is the solution?

    Cheers

    Sean.
    Sean Farrow, Aug 31, 2008
    #1
    1. Advertising

  2. Sean Farrow

    Ian Collins Guest

    Paavo Helde wrote:
    > "Sean Farrow" <> kirjutas:
    >
    >> Hi:
    >> When compiling the folowing code under visual c++ 2005 I get he
    >> following error:
    >> C3848: expression having type 'const BitSetComp' would lose some
    >> const-volatile qualifiers in order to call 'const bool
    >> BitSetComp::eek:perator ()(const KeyType &,const KeyType &)'
    >> This is in the file xtree on line 1174. The code causing this is:
    >> struct BitSetComp
    >>
    >> {
    >>
    >> bool const operator()(const KeyType& lhs, const KeyType& rhs)

    >
    > Not enough info, but try:
    >
    > bool operator() const (const KeyType& lhs, const KeyType& rhs)
    >

    Or if you want it to compile,

    bool operator()(const KeyType& lhs, const KeyType& rhs) const

    --
    Ian Collins.
    Ian Collins, Aug 31, 2008
    #2
    1. Advertising

  3. Sean Farrow

    Sean Farrow Guest

    Hi:
    Thanks both, compiles successfully.
    Sean.
    "Ian Collins" <> wrote in message
    news:...
    > Paavo Helde wrote:
    >> "Sean Farrow" <> kirjutas:
    >>
    >>> Hi:
    >>> When compiling the folowing code under visual c++ 2005 I get he
    >>> following error:
    >>> C3848: expression having type 'const BitSetComp' would lose some
    >>> const-volatile qualifiers in order to call 'const bool
    >>> BitSetComp::eek:perator ()(const KeyType &,const KeyType &)'
    >>> This is in the file xtree on line 1174. The code causing this is:
    >>> struct BitSetComp
    >>>
    >>> {
    >>>
    >>> bool const operator()(const KeyType& lhs, const KeyType& rhs)

    >>
    >> Not enough info, but try:
    >>
    >> bool operator() const (const KeyType& lhs, const KeyType& rhs)
    >>

    > Or if you want it to compile,
    >
    > bool operator()(const KeyType& lhs, const KeyType& rhs) const
    >
    > --
    > Ian Collins.
    Sean Farrow, Aug 31, 2008
    #3
  4. Sean Farrow

    Fraser Ross Guest

    "Ian Collins"
    > Or if you want it to compile,
    >
    > bool operator()(const KeyType& lhs, const KeyType& rhs) const
    >



    Is there any reason to make one non-constant? A functor wouldn't be
    adaptable if it wasn't constant.


    Fraser.
    Fraser Ross, Aug 31, 2008
    #4
    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. Allan Bruce

    To STL or not to STL

    Allan Bruce, Oct 16, 2003, in forum: C++
    Replies:
    41
    Views:
    1,010
    Christopher Benson-Manica
    Oct 17, 2003
  2. Replies:
    1
    Views:
    269
    Victor Bazarov
    Oct 22, 2005
  3. Replies:
    4
    Views:
    781
    Daniel T.
    Feb 16, 2006
  4. Replies:
    2
    Views:
    539
    klaus hoffmann
    Feb 22, 2006
  5. Rui Maciel
    Replies:
    1
    Views:
    346
    Michael Doubez
    Mar 2, 2010
Loading...

Share This Page