Which is better declare variables in for & member function in a class [duplicate]

I'm a little confused about which is better or correct to declare a function in "for" & "member function" in a class. I think the best way is trying not to make these cases...

Here are some examples.

template<typename K> class Bigger {
public:
    bool operator()(const K& a, const K& b) const {
    int aa = a.getValueJ() * a.getValueK();
    int bb = b.getValueJ() * b.getValueK();

    return aa > bb;
    }
};

template<typename K> class Bigger {
public:
    bool operator()(const K& a, const K& b) const {
      return (a.getValueJ() * a.getValueK()) > (b.getValueJ() * b.getValueK());
    }
};

=======================================

for (auto i : time1) {
  int t = t.getValueJ() / t.getValueK();
      cout << t << " ";
}

for (auto i : time1) {
     cout << t.getValueJ() / t.getValueK() << " ";
}

It seems like a very novice question.

Could you give me a little advice for them?

Have a nice day~



Read more here: https://stackoverflow.com/questions/64944044/which-is-better-declare-variables-in-for-member-function-in-a-class

Content Attribution

This content was originally published by Hyeongseok Yang at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: