Discard qualifiers

Discussion in 'C Programming' started by john, Jan 13, 2010.

  1. john

    john Guest

    Hi,
    I'm trying to sort a vector using
    sort(corelist.begin(),corelist.end());
    so I've provided a method to overload the < operator in the file, like
    so, but it isn't a class member and the code which uses it is in
    another file containing a class which inherits from this class:

    bool operator< ( const Core& a, const Core& b) {
    return a.getdistance() < b.getdistance();

    }

    Only problem is I get a const discard qualifiers error, which seems
    very annoying. It seems to make me choose whether I want to hide my
    code's variables or have them const. Removing the const seems to allow
    the program to compile but there are a lot of errors (top line of
    which shown below). getdistance just returns a double and I'm using
    gcc. I haven't got a == operator in the code, but think I may possibly
    need one.

    Any help would be gratefully received

    /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_algo.h:
    In function 'void std::partial_sort(_RandomAccessIterator,
    _RandomAccessIterator, _RandomAccessIterator) [with
    _RandomAccessIterator = __gnu_cxx::__normal_iterator<Core*,
    std::vector<Core, std::allocator<Core> > >]':
    john, Jan 13, 2010
    #1
    1. Advertising

  2. john

    Ben Pfaff Guest

    john <> writes:

    > I'm trying to sort a vector using
    > sort(corelist.begin(),corelist.end());
    > so I've provided a method to overload the < operator in the file, like
    > so, but it isn't a class member and the code which uses it is in
    > another file containing a class which inherits from this class:


    You are likely to get better responses to C++ questions in
    comp.lang.c++.
    --
    Ben Pfaff
    http://benpfaff.org
    Ben Pfaff, Jan 13, 2010
    #2
    1. Advertising

  3. john

    Seebs Guest

    On 2010-01-13, john <> wrote:
    > bool operator< ( const Core& a, const Core& b) {


    You might want comp.lang.c++.

    Alternatively, I could just point out that this is a syntax error and
    won't compile, and that's probably your problem.

    Your call. :)

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Jan 13, 2010
    #3
  4. john

    Phil Carmody Guest

    Ben Pfaff <> writes:
    > john <> writes:
    >
    >> I'm trying to sort a vector using
    >> sort(corelist.begin(),corelist.end());
    >> so I've provided a method to overload the < operator in the file, like
    >> so, but it isn't a class member and the code which uses it is in
    >> another file containing a class which inherits from this class:

    >
    > You are likely to get better responses to C++ questions in
    > comp.lang.c++.


    You lose.

    Please evolve a defence mechanism against such completely
    obvious trolls.
    c.f. http://bytes.com/topic/c/answers/698289-discard-qualifiers
    dating back to 2007.

    --
    Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
    Phil Carmody, Jan 14, 2010
    #4
  5. john

    Ben Pfaff Guest

    Phil Carmody <> writes:

    > Ben Pfaff <> writes:
    >> john <> writes:
    >>
    >>> I'm trying to sort a vector using
    >>> sort(corelist.begin(),corelist.end());
    >>> so I've provided a method to overload the < operator in the file, like
    >>> so, but it isn't a class member and the code which uses it is in
    >>> another file containing a class which inherits from this class:

    >>
    >> You are likely to get better responses to C++ questions in
    >> comp.lang.c++.

    >
    > Please evolve a defence mechanism against such completely
    > obvious trolls.
    > c.f. http://bytes.com/topic/c/answers/698289-discard-qualifiers
    > dating back to 2007.


    I'm not going to spend more time searching for a reason to call
    an article a troll than I would spend writing up a completely
    reasonable answer to it.
    --
    Ben Pfaff
    http://benpfaff.org
    Ben Pfaff, Jan 14, 2010
    #5
  6. john

    Phil Carmody Guest

    Ben Pfaff <> writes:
    > Phil Carmody <> writes:
    >
    >> Ben Pfaff <> writes:
    >>> john <> writes:
    >>>
    >>>> I'm trying to sort a vector using
    >>>> sort(corelist.begin(),corelist.end());
    >>>> so I've provided a method to overload the < operator in the file, like
    >>>> so, but it isn't a class member and the code which uses it is in
    >>>> another file containing a class which inherits from this class:
    >>>
    >>> You are likely to get better responses to C++ questions in
    >>> comp.lang.c++.

    >>
    >> Please evolve a defence mechanism against such completely
    >> obvious trolls.
    >> c.f. http://bytes.com/topic/c/answers/698289-discard-qualifiers
    >> dating back to 2007.

    >
    > I'm not going to spend more time searching for a reason to call
    > an article a troll than I would spend writing up a completely
    > reasonable answer to it.


    So what? I did not suggest that you spend any time *searching* for
    a reason to *call* an article a troll. I suggested that you evolve
    an ability to detect such completely obvious trolls without needing
    to perform a search, and that once you've so detected them, there's
    no need for any response at all.

    Phil
    --
    Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
    Phil Carmody, Jan 14, 2010
    #6
  7. john

    Ben Pfaff Guest

    Phil Carmody <> writes:

    > Ben Pfaff <> writes:
    >> Phil Carmody <> writes:
    >>> Please evolve a defence mechanism against such completely
    >>> obvious trolls.

    >>
    >> I'm not going to spend more time searching for a reason to call
    >> an article a troll than I would spend writing up a completely
    >> reasonable answer to it.

    >
    > So what? I did not suggest that you spend any time *searching* for
    > a reason to *call* an article a troll. I suggested that you evolve
    > an ability to detect such completely obvious trolls without needing
    > to perform a search, and that once you've so detected them, there's
    > no need for any response at all.


    I don't know how you tell the difference between an article
    carelessly posted to the wrong newsgroup and a troll. To me, the
    article resembled the former more than the latter.
    --
    Ben Pfaff
    http://benpfaff.org
    Ben Pfaff, Jan 14, 2010
    #7
  8. On 14 Jan, 22:30, Phil Carmody <>
    wrote:
    > Ben Pfaff <> writes:
    > > Phil Carmody <> writes:

    >
    > >> Ben Pfaff <> writes:
    > >>> john <> writes:

    >
    > >>>> I'm trying to sort a vector using
    > >>>>         sort(corelist.begin(),corelist.end());
    > >>>> so I've provided a method to overload the < operator in the file, like
    > >>>> so, but it isn't a class member and the code which uses it is in
    > >>>> another file containing a class which inherits from this class:

    >
    > >>> You are likely to get better responses to C++ questions in
    > >>> comp.lang.c++.

    >
    > >> Please evolve a defence mechanism against such completely
    > >> obvious trolls.
    > >> c.f.http://bytes.com/topic/c/answers/698289-discard-qualifiers
    > >> dating back to 2007.

    >
    > > I'm not going to spend more time searching for a reason to call
    > > an article a troll than I would spend writing up a completely
    > > reasonable answer to it.

    >
    > So what? I did not suggest that you spend any time *searching* for
    > a reason to *call* an article a troll. I suggested that you evolve
    > an ability to detect such completely obvious trolls without needing
    > to perform a search,


    how?

    > and that once you've so detected them, there's
    > no need for any response at all.
    Nick Keighley, Jan 15, 2010
    #8
    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. David Smith
    Replies:
    2
    Views:
    369
    Shane Petroff
    Jul 24, 2003
  2. Leif K-Brooks
    Replies:
    5
    Views:
    325
    David Fraser
    Apr 15, 2005
  3. Replies:
    1
    Views:
    246
  4. gobis
    Replies:
    4
    Views:
    496
  5. Jim

    Discard qualifiers

    Jim, Aug 24, 2007, in forum: C++
    Replies:
    2
    Views:
    1,039
    Rolf Magnus
    Aug 24, 2007
Loading...

Share This Page