I wasn't sure if this question should go here or somewhere else.

I'm trying to document my C++ code but I'm having trouble describing things without being verbose.

So let's say I have a class Number

class Number {
private:
   int data;
public:
   int subtract(Number inNumber);
}

The method subtract is as follows:

int Number::subtract(Number inNumber) {
   return (this->data - inNumber.data);
}

The method Number::subtract functions as follows: So let's say we have 2 instances of Number, foo and bar, both have been initialized properly and have their respective data. If I do

foo.subtract(bar);

The program does

return (foo.data - bar.data)

Now if I were to document Number::subtract, I could refer to bar as "the entered Number". But how exactly do I refer to foo?

"this Number" as in "The function returns the subtracts the entered Number from this Number" doesn't sound quite right. Neither does "the main Number". I'm not sure what the exact term is.

1

There are 1 best solutions below

0
Charps On

If you wanted to do it this way, you would want to do documentation like:

/**
 * @return The passed number subtracted from this number.
 */

You would also want to make this a constant function to make it clear that it doesn't affect any class members.

An alternative way you could do this is by using C++ custom operators. If you name the function operator-, then the following code will be the same:

foo.operator-(bar);
foo - bar;

For more information on this alternative, please reference this article.