Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Setters with and without this pointer.
QtWS25 Last Chance

Setters with and without this pointer.

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 2 Posters 427 Views
  • 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on 12 Nov 2019, 14:26 last edited by
    #1

    When QtCreator creates setters for class properties, it uses the attribute directly, ie.

    void Models::ZipCode::setZipcode(const QString &value)
    {
    	zipcode = value;
    }
    

    But I'm used to always using the this pointer:

    void Models::ZipCode::setZipcode(const QString &value)
    {
    	this->zipcode = value;
    }
    

    Are there any differences between these approaches or are they equivalent?

    J 1 Reply Last reply 12 Nov 2019, 14:34
    0
    • E Exotic_Devel
      12 Nov 2019, 14:26

      When QtCreator creates setters for class properties, it uses the attribute directly, ie.

      void Models::ZipCode::setZipcode(const QString &value)
      {
      	zipcode = value;
      }
      

      But I'm used to always using the this pointer:

      void Models::ZipCode::setZipcode(const QString &value)
      {
      	this->zipcode = value;
      }
      

      Are there any differences between these approaches or are they equivalent?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 12 Nov 2019, 14:34 last edited by
      #2

      @Exotic_Devel they are equivalent , as long as the member variable and the argument do not share the exact same name.

      But why would you insist on always writing this-> this isn't Python !


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      E 1 Reply Last reply 12 Nov 2019, 14:37
      1
      • J J.Hilk
        12 Nov 2019, 14:34

        @Exotic_Devel they are equivalent , as long as the member variable and the argument do not share the exact same name.

        But why would you insist on always writing this-> this isn't Python !

        E Offline
        E Offline
        Exotic_Devel
        wrote on 12 Nov 2019, 14:37 last edited by
        #3

        @J-Hilk said in Setters with and without this pointer.:

        But why would you insist on always writing this-> this isn't Python !

        Habit I acquired when I started using Java. :)

        J 1 Reply Last reply 12 Nov 2019, 14:38
        2
        • E Exotic_Devel
          12 Nov 2019, 14:37

          @J-Hilk said in Setters with and without this pointer.:

          But why would you insist on always writing this-> this isn't Python !

          Habit I acquired when I started using Java. :)

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 12 Nov 2019, 14:38 last edited by J.Hilk 11 Dec 2019, 14:40
          #4

          @Exotic_Devel said in Setters with and without this pointer.:

          @J-Hilk said in Setters with and without this pointer.:

          But why would you insist on always writing this-> this isn't Python !

          Habit I acquired when I started using Java. :)

          Ah, my condolences!
          😉


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1

          4/4

          12 Nov 2019, 14:38

          • Login

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