Added a small micro example of the problem with SFML's use of const on drawable virtual functions which shows the _real_ reason they did this is because of a poor design decision to make both Drawable and RenderTarget equally in charge of drawing the other. AKA the 'Deadly Embrace' design flaw.
parent
b8395c6d9f
commit
5f25383891
@ -0,0 +1,24 @@ |
||||
#include <iostream> |
||||
#include "constness.hpp" |
||||
|
||||
using std::cout; |
||||
|
||||
void RenderTarget::draw(const Drawable& drawable) { |
||||
drawable.draw(*this); |
||||
} |
||||
|
||||
void Shape::draw(const RenderTarget& target) const { |
||||
cout << "shape draw\n"; |
||||
} |
||||
|
||||
using std::cout; |
||||
|
||||
int main() { |
||||
|
||||
RenderTarget target; |
||||
Shape shape; |
||||
|
||||
target.draw(shape); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,18 @@ |
||||
#pragma once |
||||
|
||||
class Drawable; |
||||
|
||||
class RenderTarget { |
||||
public: |
||||
void draw(const Drawable& drawable); |
||||
}; |
||||
|
||||
class Drawable { |
||||
public: |
||||
virtual void draw(const RenderTarget& target) const = 0; |
||||
}; |
||||
|
||||
class Shape : public Drawable { |
||||
public: |
||||
void draw(const RenderTarget& target) const override; |
||||
}; |
Loading…
Reference in new issue