Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I cannot create operators for my class

I cannot create operators for my class

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 619 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    Hello

    I try to create operators for my class
    in the header I have
    @
    class Connectoin{
    public :
    .
    .
    .
    bool operator()(const Connection &first, const Connection &other) const;
    bool operator<(const Connection &other) const;
    private:
    .
    .
    .
    @
    and in the source file I implement it

    @
    bool Connection::operator()(const Connection &first, const Connection &other)const
    {
    return (first.getName() < other.getName());
    }

    bool Connection::operator<(const Connection &other)const
    {
    return (this->name < other.getName());
    }
    @
    all getter methods I have defines as const,
    The error is "passing 'const Connection' as 'this' argument of 'const QString Connection::getName()' discards qualifiers [-fpermissive]"

    what should I do?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      bq. what should I do?

      Post here the code of getName() ;)

      The error is not about operators, but that getName has a non-const context. Are you 100% sure the signature of getName() is const? The compiler seems to disagree on that ;)

      const QString Connection::getName() returns a const QString (which is weird really) but the method is not const itself. It should be QString Connection::getName() const

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved