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 6384837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:49:30+00:00 2026-05-25T02:49:30+00:00

I templatized a class earlier and as a result of this templatization, all classes

  • 0

I templatized a class earlier and as a result of this templatization, all classes that received objects of this newly templated type require templating as well, even where the templatization is completely irrelevant.

So:

  • class Shape is the base class for class Sphere, Cube, Model
  • Each Shape contains a Mesh
  • Mesh has now been templatized to allow for basically the VertexBuffer to have a parameterized type:

So:

template <typename T> struct Mesh
{
    VertexBuffer<T> verts ; // Mesh needs to be templated to allow
    // the vertex buffer to be templated as well
} ;

So now the class that contains the Mesh (base class Shape) needs to be templated as well:

template <typename T> class Shape
{
    Mesh<T>* mesh ;
} ;

And now, all the methods anywhere in the code need to be templated as well, even where that templatization in no way affects the code (ie that code has no business with the vertex type of the Mesh member)

So for example, the octree node:

// An octree node
template <typename T> struct ONode // but this class doesn't really benefit
                                   // from templatization
{
    AABB bounds ;
    ONode* parent ; // facilitate movement thru the tree
    ONode* children[8]; // cells, octants, cubelets
    Shape<T>* objects ;    // for the purposes of the Octree,
                        // But ALL SHAPES BEHAVE THE SAME. <T> serves no purpose

This is a really nasty artifact and I’m not sure how to stop the perculation of templatization at an earlier point, or if templatization was a correct choice now that I see how much needs to be templatized.

  • 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-25T02:49:30+00:00Added an answer on May 25, 2026 at 2:49 am

    I would suggest you create a non-templated base class for Mesh (or VertexBuffer, whichever makes the most sense) that exposes the functionality that doesn’t depend on the template, and use that in other places. For example:

    class MeshBase
    {
        // Functionality that doesn't depend on the template type.
    };
    
    template<typename T>
    class Mesh : public MeshBase
    {
        // Functionality that does depend on the template type.
    };
    

    This does mean that you may more frequently need to deal with dynamically allocated values of this type and pass them around as pointers, but some judicious use of smart pointers should alleviate that burden.


    In general, there is a certain friction between using object oriented principles and generic programming principles, some of which you’ve discovered here. Whenever this happens, you essentially need a class that can hold the value of multiple generic types and models the common behavior, without the consumer needing to know the templated type. Sometimes, this can be done even if the types have no common base. This technique is called type erasure and this article by Thomas Becker provides some insight into this matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a templated container class that looks something like this: template <class ItemType>
I have non-template class with a templatized constructor. This code compiles for me. But
I have a dll that contains a templated class. Is there a way to
I'm writing a logging class that uses a templatized operator<< function. I'm specializing the
I have a templated class Vector<class T, int N> Where T is the type
I have several small classes that are all peers of each other declared and
i have a templated class, with the following definition: ImageRescaleDepth<PIXEL_TYPE_INPUT, PIXEL_TYPE_OUTPUT> This class uses
I declare a templated class with all parameters having default arguments, for example: template<typename
Let's say I have some templated class depending on type T . T could
This could probably be generalized to any templated class, but I've run into this

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.