diff --git a/meson.build b/meson.build index 10b19e6..599b5fc 100644 --- a/meson.build +++ b/meson.build @@ -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) diff --git a/sfml-const/constness.cpp b/sfml-const/constness.cpp index 9d88955..275ea98 100644 --- a/sfml-const/constness.cpp +++ b/sfml-const/constness.cpp @@ -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; diff --git a/sfml-const/constness.hpp b/sfml-const/constness.hpp index 2ced61c..f9c3554 100644 --- a/sfml-const/constness.hpp +++ b/sfml-const/constness.hpp @@ -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; }; diff --git a/sfml-const/fixed.cpp b/sfml-const/fixed.cpp new file mode 100644 index 0000000..338273a --- /dev/null +++ b/sfml-const/fixed.cpp @@ -0,0 +1,17 @@ +#include +#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; +} diff --git a/sfml-const/fixed.hpp b/sfml-const/fixed.hpp new file mode 100644 index 0000000..54e18c5 --- /dev/null +++ b/sfml-const/fixed.hpp @@ -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; +};