Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4094748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:47:12+00:00 2026-05-20T19:47:12+00:00

I’ve been teaching game programming and I’ve spent a lot of time talking about

  • 0

I’ve been teaching game programming and I’ve spent a lot of time talking about breaking dependencies with the goal that old code should not change if new code is introduced. We were setting up a renderer object and I decided to templatize the render function so I could show some uses for traits classes, etc. But this led to an interesting idea.

If I never provide a generic body and only provide full specializations then the render class can be extended regarding what it can render from outside code and if an object is rendered that does not have full specialization, the compiler fails rather than the exe. This allows games using this system a chance to build custom renderable objects and extend the functionality without needing to change the renderer hpp or cpp files.

Is this a known design pattern, or is it a terrible idea and why, or has anyone else done this? I’d love to know if there is a serious problem here because all I see are positives.

Thanks all.

Here’s the code formated.

I’m doing it a little different so client code doesn’t know it’s a template.

class Renderer
{
public:
    void SwapBuffers();

    template<typename RenderObj>
    void Render(const RenderObj&);
};

// Full specializations
class Sprite;
template<> void Renderer::Render<Sprite>(const Sprite&);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:47:13+00:00Added an answer on May 20, 2026 at 7:47 pm

    If I’m correctly understanding your description:

    template <class> class render; // undefined
    
    template <>
    class render<Object1>
    {
       // ...
    };
    
    template <>
    class render<Object2>
    {
       // ...
    };
    
    // ...
    

    I consider this a valid approach. Sometimes you can fill out the general case primary template, and sometimes you can’t. And a compile time error to indicate when you can’t is superior to a run time error (as you said).

    I would say the design pattern is known, though I can’t put a name to it. std::function in C++11 follows a similar pattern, although clients don’t usually supply a specialization (though theoretically could):

    template <class> class function; // undefined
    
    template<class R, class... ArgTypes>
    class function<R(ArgTypes...)>
    {
      // ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.