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.
Forum Updated to NodeBB v4.3 + New Features

Setters with and without this pointer.

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 2 Posters 434 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on 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.HilkJ 1 Reply Last reply
    0
    • E Exotic_Devel

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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
      1
      • J.HilkJ J.Hilk

        @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 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.HilkJ 1 Reply Last reply
        2
        • E Exotic_Devel

          @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.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #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

          • Login

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