Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Extract Function is not taking the arguments as a Reference variable
Forum Updated to NodeBB v4.3 + New Features

Extract Function is not taking the arguments as a Reference variable

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
2 Posts 2 Posters 580 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.
  • keksi venksiK Offline
    keksi venksiK Offline
    keksi venksi
    wrote on last edited by keksi venksi
    #1

    Hi !!!!!!

    Currently Im working on Qt 5.6.2 . Im Pretty Happy in this enhanced version . In order to have a good code readability I'm reducing the code length of all the functions such as If i have 100 lines of code Im making 10 functions (Each function has 10 lines ) and calling respectively . Im achieving it by EXTRACT FUNCTION feature in Qt . Everything goes fine . When i Do extract function initially the arguments in the newly created method is a reference variable , so that if we change any value of the variable it will update in the function which we are calling . As of now all is fine . But later after few days If i do extract function , the arguments in the new function is not a reference variable . Can any one please help me on how to extract function with refrence variable

    jsulmJ 1 Reply Last reply
    0
    • keksi venksiK keksi venksi

      Hi !!!!!!

      Currently Im working on Qt 5.6.2 . Im Pretty Happy in this enhanced version . In order to have a good code readability I'm reducing the code length of all the functions such as If i have 100 lines of code Im making 10 functions (Each function has 10 lines ) and calling respectively . Im achieving it by EXTRACT FUNCTION feature in Qt . Everything goes fine . When i Do extract function initially the arguments in the newly created method is a reference variable , so that if we change any value of the variable it will update in the function which we are calling . As of now all is fine . But later after few days If i do extract function , the arguments in the new function is not a reference variable . Can any one please help me on how to extract function with refrence variable

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @keksi-venksi You can simply change them to references (just & in front of the parameter name). Although you should avoid non-const references as it is not possible to know whether a function/method is changing its parameters without checking the function/method signature:

      int a = 10;
      myFunction(a); // Does myFunction change a or not?
      

      If a function is changing something it should return it as its return value:

      int a = 10;
      a = myFunction(a);
      

      One general note: making 10 functions out of a 100 lines function sounds somehow wrong. You should decide which and how many functions you need based on design and not on number of lines. It can be perfectly fine to divide 100 lines function into, for example, four functions.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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