Skip to main content
Fix typo and expand example
Source Link
1201ProgramAlarm
  • 7.8k
  • 2
  • 23
  • 39

You're passing fundamental types by const reference. These are better off just being passed by value. So you'd get things like

explicit address(uint32_t value);
reference operator[](int index) noexcept(false);

Your prefix increment and decrement operators should return a reference to the incremented value.

address operator++&operator++(); { /* ... */ return *this; }
address operator&operator--(); { /* ... */ return *this; }

This will allow expressions like addr = ++other_addr;. (Note that, since you're in the address class, you can just name the class, you don't need to specify scope with ::ip::address).

Your postfix increment and decrement operators have a bug, because they return a reference to a local variable. The return types should be a value.

address operator++(int);
address operator--(int);

For readability and clarity, expressions mixing shifts and bit masking should use parentheses:

data_[0] = (value >> 24) & 0xFF;

You're passing fundamental types by const reference. These are better off just being passed by value. So you'd get things like

explicit address(uint32_t value);
reference operator[](int index) noexcept(false);

Your prefix increment and decrement operators should return a reference to the incremented value.

address operator++();
address operator--();

This will allow expressions like addr = ++other_addr;. (Note that, since you're in the address class, you can just name the class, you don't need to specify scope with ::ip::address).

Your postfix increment and decrement operators have a bug, because they return a reference to a local variable. The return types should be a value.

address operator++(int);
address operator--(int);

For readability and clarity, expressions mixing shifts and bit masking should use parentheses:

data_[0] = (value >> 24) & 0xFF;

You're passing fundamental types by const reference. These are better off just being passed by value. So you'd get things like

explicit address(uint32_t value);
reference operator[](int index) noexcept(false);

Your prefix increment and decrement operators should return a reference to the incremented value.

address &operator++() { /* ... */ return *this; }
address &operator--() { /* ... */ return *this; }

This will allow expressions like addr = ++other_addr;. (Note that, since you're in the address class, you can just name the class, you don't need to specify scope with ::ip::address).

Your postfix increment and decrement operators have a bug, because they return a reference to a local variable. The return types should be a value.

address operator++(int);
address operator--(int);

For readability and clarity, expressions mixing shifts and bit masking should use parentheses:

data_[0] = (value >> 24) & 0xFF;
Source Link
1201ProgramAlarm
  • 7.8k
  • 2
  • 23
  • 39

You're passing fundamental types by const reference. These are better off just being passed by value. So you'd get things like

explicit address(uint32_t value);
reference operator[](int index) noexcept(false);

Your prefix increment and decrement operators should return a reference to the incremented value.

address operator++();
address operator--();

This will allow expressions like addr = ++other_addr;. (Note that, since you're in the address class, you can just name the class, you don't need to specify scope with ::ip::address).

Your postfix increment and decrement operators have a bug, because they return a reference to a local variable. The return types should be a value.

address operator++(int);
address operator--(int);

For readability and clarity, expressions mixing shifts and bit masking should use parentheses:

data_[0] = (value >> 24) & 0xFF;