From c800ddb3486c02e4497d07e4b7138d02f9da8e6b Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 9 Feb 2025 21:37:57 -0500 Subject: [PATCH] Better version that still has both functions, but asserts a warning when misused, or you can implement it if you need. --- sfml-const/fix2.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sfml-const/fix2.cpp b/sfml-const/fix2.cpp index 34a4ddd..83984fc 100644 --- a/sfml-const/fix2.cpp +++ b/sfml-const/fix2.cpp @@ -1,5 +1,6 @@ #include #include "fix2.hpp" +#include using std::cout; @@ -8,19 +9,21 @@ void RenderTarget::draw(const Drawable& drawable) { } void Shape::draw(RenderTarget& target) const { - cout << "shape draw\n"; + assert(false && "You should not call this, use shape.draw(target) instead."); } void Shape::draw(RenderTarget &target) { - cout << "shape non-const instead\n"; + cout << "shape renders without const instead\n"; } int main() { RenderTarget target; Shape shape; - target.draw(shape); + // uncomment this to see the error when used wrong + // target.draw(shape); shape.draw(target); + return 0; }