Better version that still has both functions, but asserts a warning when misused, or you can implement it if you need.

master
Zed A. Shaw 2 months ago
parent c1f1eee58b
commit c800ddb348
  1. 9
      sfml-const/fix2.cpp

@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include "fix2.hpp" #include "fix2.hpp"
#include <cassert>
using std::cout; using std::cout;
@ -8,19 +9,21 @@ void RenderTarget::draw(const Drawable& drawable) {
} }
void Shape::draw(RenderTarget& target) const { 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) { void Shape::draw(RenderTarget &target) {
cout << "shape non-const instead\n"; cout << "shape renders without const instead\n";
} }
int main() { int main() {
RenderTarget target; RenderTarget target;
Shape shape; Shape shape;
target.draw(shape); // uncomment this to see the error when used wrong
// target.draw(shape);
shape.draw(target); shape.draw(target);
return 0; return 0;
} }

Loading…
Cancel
Save