The fix is simple: Just don't have RenderTarget (which is literally named render TARGET) also be in charge of rendering things to itself.

master
Zed A. Shaw 2 months ago
parent 5f25383891
commit 9410d37d12
  1. 6
      meson.build
  2. 5
      sfml-const/constness.cpp
  3. 4
      sfml-const/constness.hpp
  4. 17
      sfml-const/fixed.cpp
  5. 16
      sfml-const/fixed.hpp

@ -50,6 +50,10 @@ executable('rvo_test', [
override_options: exe_defaults,
dependencies: dependencies)
executable('constness', 'sfml-const/constness.cpp',
executable('sfml-constness', 'sfml-const/constness.cpp',
override_options: exe_defaults,
dependencies: dependencies)
executable('sfml-fixed1', 'sfml-const/fixed.cpp',
override_options: exe_defaults,
dependencies: dependencies)

@ -7,14 +7,11 @@ void RenderTarget::draw(const Drawable& drawable) {
drawable.draw(*this);
}
void Shape::draw(const RenderTarget& target) const {
void Shape::draw(RenderTarget& target) const {
cout << "shape draw\n";
}
using std::cout;
int main() {
RenderTarget target;
Shape shape;

@ -9,10 +9,10 @@ class RenderTarget {
class Drawable {
public:
virtual void draw(const RenderTarget& target) const = 0;
virtual void draw(RenderTarget& target) const = 0;
};
class Shape : public Drawable {
public:
void draw(const RenderTarget& target) const override;
void draw(RenderTarget& target) const override;
};

@ -0,0 +1,17 @@
#include <iostream>
#include "constness.hpp"
using std::cout;
void Shape::draw(RenderTarget& target) const {
cout << "shape draw\n";
}
int main() {
RenderTarget target;
Shape shape;
shape.draw(target);
return 0;
}

@ -0,0 +1,16 @@
#pragma once
class Drawable;
class RenderTarget {
};
class Drawable {
public:
virtual void draw(RenderTarget& target) = 0;
};
class Shape : public Drawable {
public:
void draw(RenderTarget& target) const override;
};
Loading…
Cancel
Save