Actually this works, so...yeah why don't they just do this?

master
Zed A. Shaw 2 months ago
parent 6f346f3357
commit c1f1eee58b
  1. 6
      sfml-const/fix2.cpp
  2. 7
      sfml-const/fix2.hpp

@ -11,8 +11,8 @@ void Shape::draw(RenderTarget& target) const {
cout << "shape draw\n"; cout << "shape draw\n";
} }
void Shape::render_to(RenderTarget &target) { void Shape::draw(RenderTarget &target) {
cout << "shape render_to instead\n"; cout << "shape non-const instead\n";
} }
int main() { int main() {
@ -21,6 +21,6 @@ int main() {
target.draw(shape); target.draw(shape);
shape.render_to(target); shape.draw(target);
return 0; return 0;
} }

@ -13,15 +13,16 @@ class Drawable {
* NOTE: This requires const because RenderTarget * NOTE: This requires const because RenderTarget
* pass itself in as a *this which is always const. * pass itself in as a *this which is always const.
* If you need to draw without const then invert it * If you need to draw without const then invert it
* then use shape.render_to(target) instead. * then use shape.draw(target) instead, which is
* not const.
*/ */
virtual void draw(RenderTarget& target) const = 0; virtual void draw(RenderTarget& target) const = 0;
virtual void render_to(RenderTarget& target) = 0; virtual void draw(RenderTarget& target) = 0;
}; };
class Shape : public Drawable { class Shape : public Drawable {
public: public:
void draw(RenderTarget& target) const override; void draw(RenderTarget& target) const override;
void render_to(RenderTarget &target) override; void draw(RenderTarget& target) override;
}; };

Loading…
Cancel
Save