Jump to content
  • Advertisement
Sign in to follow this  
ShaChris23

Cost of pure virtual

This topic is 3978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I posted my question here because they had a better code formatting: http://www.qtcentre.org/forum/f-general-programming-9/t-cost-of-pure-virtual-9988.html What's your opinion?

Share this post


Link to post
Share on other sites
Advertisement
The second form is faster than the first, because the compiler has access to more static binding information. The first form is a better design, because it factors out a lot of code repetition (it's the Template pattern). The first should be used unless it proves noticeably slow, at which point the second should be used instead (with static type hints built on top of the first one).

Ultimately, since your various steps (setup, processing, value returning) seem disparate, you might wish to use a composition-based design instead of an inheritance-based design, and use a template hierarchy to simplify the issues:

class Task { public: virtual void Execute() = 0; };

template<typename Object>
class RealTask : Task
{
Object::value_type value;
public:
void Execute()
{
Object::setup(this -> value);
Object::process(this -> value);
Object::return_value(this -> value);
}
};

// Define objects of the "Object" archetype (a value type,
// and setup/process/return functions which may be const static
// function pointers to existing functions or typedefs to
// existing types used by other Object implementations)



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!