I forgot that I was accessing x publicly instead of calling the appropriate functions to set it ... which undermined the whole proof.
This commit is contained in:
		
							
								
								
									
										8
									
								
								Ball.h
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								Ball.h
									
									
									
									
									
								
							@@ -12,14 +12,16 @@ public:
 | 
				
			|||||||
			instance_num = ++instance_counter;
 | 
								instance_num = ++instance_counter;
 | 
				
			||||||
			// NOTE(dev): don't go above 100, please, for the sake of the example.
 | 
								// 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)
 | 
						static void SetX(int &x, void *instance)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Ball *ball = static_cast<Ball*>(instance);
 | 
								Ball *ball = static_cast<Ball*>(instance);
 | 
				
			||||||
			ball->GetXFromPhysicsSimulation();
 | 
								x = ball->GetXFromPhysicsSimulation();
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,10 +25,9 @@ public:
 | 
				
			|||||||
				callback(x, user_data);
 | 
									callback(x, user_data);
 | 
				
			||||||
			return x; // either this was just set by callback, or it was always set by constructor.
 | 
								return x; // either this was just set by callback, or it was always set by constructor.
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
//private:
 | 
					private:
 | 
				
			||||||
	int x;
 | 
						int x;
 | 
				
			||||||
	void *user_data;
 | 
						void *user_data;
 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	void (*callback)(int&, void*);
 | 
						void (*callback)(int&, void*);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user