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. [solved] two operators with the same input?
Forum Updated to NodeBB v4.3 + New Features

[solved] two operators with the same input?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 869 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.
  • B Offline
    B Offline
    billconan
    wrote on last edited by
    #1

    Hello guys,

    I'm trying the new Qt5 json feature. I found that there are two [] operators defined for QJsonObject.

    My understanding is that c++ doesn't allow this, because there is no way to tell which one is the one you want to call. They both have the same function name "operator[]" and parameter. But things can compile.

    1. QJsonValue QJsonObject::operator[](const QString & key) const
    2. QJsonValueRef QJsonObject::operator[](const QString & key)

    now, I want to call the first [] operator. I call it like this: jsonObj["key name"]; but what I actually call is the second operator, I get QJsonValueRef instead of QJsonValue.

    Question:
    How do I call the first operator?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billconan
      wrote on last edited by
      #2

      ok, found answer myself:

      http://stackoverflow.com/questions/5762042/const-overloaded-operator-function-and-its-invocation

      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