From 4daea58b699da0690e94ee00f433f8966339a353 Mon Sep 17 00:00:00 2001 From: David Vereb Date: Tue, 23 May 2017 17:04:35 -0400 Subject: [PATCH] I forgot that I was accessing x publicly instead of calling the appropriate functions to set it ... which undermined the whole proof. --- Ball.h | 8 +++++--- GraphicsObject.h | 3 +-- PhysicsObject.h | 16 ---------------- 3 files changed, 6 insertions(+), 21 deletions(-) delete mode 100644 PhysicsObject.h diff --git a/Ball.h b/Ball.h index a0deac7..a16ced0 100644 --- a/Ball.h +++ b/Ball.h @@ -12,14 +12,16 @@ public: instance_num = ++instance_counter; // NOTE(dev): don't go above 100, please, for the sake of the example. } - void GetXFromPhysicsSimulation() + int GetXFromPhysicsSimulation() { - x = instance_num + ((rand() % 10) * 100); // move around by ten, but keep single digit + // NOTE(dev): move around by 100 to show that the number is different each time, + // but keep the instance number to show you're on the same one. + return instance_num + ((rand() % 10) * 100); } static void SetX(int &x, void *instance) { Ball *ball = static_cast(instance); - ball->GetXFromPhysicsSimulation(); + x = ball->GetXFromPhysicsSimulation(); return; } diff --git a/GraphicsObject.h b/GraphicsObject.h index 8a2476e..b94fe2e 100644 --- a/GraphicsObject.h +++ b/GraphicsObject.h @@ -25,10 +25,9 @@ public: callback(x, user_data); return x; // either this was just set by callback, or it was always set by constructor. } -//private: +private: int x; void *user_data; -private: void (*callback)(int&, void*); }; diff --git a/PhysicsObject.h b/PhysicsObject.h deleted file mode 100644 index e26c7bb..0000000 --- a/PhysicsObject.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef PHYSICSOBJECT_H -#define PHYSICSOBJECT_H - -#include "IPhysics.h" - -class PhysicsObject - : public IPhysics -{ -public: - PhysicsObject() : IPhysics(&x) {} - int GetX() { Update(); return x; } -private: - int x; -}; - -#endif