Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
16.6.1 clarification
#1
Hi,

Rule 16.6.1 marks this example as non-compliant:

Code:
C operator+( int32_t rhs ) const;  // Non-compliant

However it does not provide a compliant alternative. It's unclear if rule 16.6.1 wants us to:

a) Duplicate the function and create 2 versions for each order of the parameters, in order to guarantee symmetry (even if it may not be useful for the user, potentially being dead code):

Code:
C operator+(C       lhs, int32_t rhs );
C operator+(int32_t lhs, C       rhs );

b) Implement only 1 overload, but as a non-member function. This still does not solve the problem of "operator+ must be symmetrical", i.e that "1 + c" and "c + 1" must be supported.
Code:
friend C operator+(C lhs, int32_t rhs );

Could you clarify?

Thanks!
Reply


Messages In This Thread
16.6.1 clarification - by cgpzs - 26-03-2025, 02:36 PM
RE: 16.6.1 clarification - by misra cpp - 28-03-2025, 02:17 PM
RE: 16.6.1 clarification - by cgpzs - 31-03-2025, 09:29 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)