What is the appropriate terminology in English to refer to an object in C ++?

What is the correct / suitable English terminology for referring to the "current" object in C ++. For example, say you write a comment in the body of the implementation of this:

Thing Thing::operator+(const Thing& other)

You have the variable name β€œother” to use for another object, but what word / expression do you use to refer to the object that performs the operation?

+3
source share
10 answers

In C ++, it is called an object thisand what I use.

: operator+() . += ( , , ) operator+ :

inline Thing operator+(Thing lhs, const Thing& rhs)
{
  lhs += rhs;
  return lhs;
}

(: lhs const , , .)

+11

"this" , . , ++, , "this" . , , BS "" "this".

+6

"this", , , " ". :

/** \brief Adds another Thing to this instance.
 * A reference to this instance is returned.
*/
Thing& Thing::operator+(const Thing& other);

Doxygen , .

+3

, : . . " ".

, , . ++, *this . . " *this, , Thing:: foo, 0 (. # 42)"

+3

, this . " ".

+2

" " " ", .

+2

"this", "ourself" ( , "" , ).

, "<whatever>". ( , , ), " " " <whatever>". <whatever> - , - , , .

/**
 * An utterly useless write-only counter, with arbitrary initial value.
 */
class Counter {
    unsigned int count;
public:
    /** 
     * Increments the counter
     */
    Counter &operator++() {
        // We need to add 1 to ourself. I found a snippet online that does it:
        ++count;
        // return ourself
        return *this;
    }
    /**
     * Adds together this counter and "other".
     */
    Counter operator+(const Counter &other) const {
        Counter result;
        // new count is our count plus other count
        result.count = count + other.count;
        return result;
    }
};
0

, lhs rhs ( ).

, this. (, ). pThis.

, , "" . " ".

0

, , , .

0

++ , - .

-2
source

Source: https://habr.com/ru/post/1725610/


All Articles