In this post, we will see how to resolve C++ Reuse out-of-class comparsion operators of base for derived class
Question:
Snippetb1 == b2
work without a static_cast
?
Is a reuse of the out-of-class comparison operators of A
possible without redefining explicit comparison operators for B
?Example on godbolt
EDIT: I forgot to mention that
A
is immutable to me. I have no access to it and its comparison operators.Best Answer:
Is it possible to make the last comparison b1 == b2 work without a static_cast?
Yes, you can use SFINAE as shown below:
Or with C++20 use
requires
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
Leave a Review