class Time{public: float GetDeltaTime(); ...private: Time(); ... friend class Engine;}
By going with this method, I declare friendships everywhere. I'm wondering, can this be done in some way without friendships?
Mufflot
class Time{public: float GetDeltaTime(); ...private: Time(); ... friend class Engine;}
// Time interface.class Time{protected: // protected destructor prevents the user from deleting your time object. virtual ~Time() { }public: virtual float GetDeltaTime() = 0;};// Engine interface.class Engine{public: virtual ~Engine() { } virtual Time* GetTime() = 0;};
// Class which implements the time interface.class TimeImplementation: public Time{public: TimeImplementation() { } virtual ~TimeImplementation() { } virtual float GetDeltaTime() { // TODO: Implement! return 1.0f; }};// Class which implements the engine interface.class EngineImplementation: public Engine{public: EngineImplementation() { } virtual ~EngineImplementation() { } virtual Time* GetTime() { return &iTime; }private: TimeImplementation iTime;};// Function which creates the engine.Engine* CreateEngine(){ return new EngineImplementation;}
void example(){ Engine* engine = CreateEngine(); Time* time = engine->GetTime(); float deltaTime = time->GetDeltaTime(); delete engine;}
Quote:Original post by Mufflot
Thanks for the replies!
I'm going to try out ttstreamer's solution, it looked quite nice.
Quote:Original post by Mufflot
SiCrane: Sounds like a good idea, any tips on how can you do that? I'm not at my home so I can't really try it out by myself atm.