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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:22:50+00:00 2026-05-24T21:22:50+00:00

I am currently facing a problem dealing with template classes. In the codebase I

  • 0

I am currently facing a problem dealing with template classes. In the codebase I am currently working with we have a line something like this:

Register<uint32_t>* myReg = static_cast<Register<uint32_t>*>(importItemPtr(someGlobalIdString));

where importItemPtr is responsible for returning a void* to an item from some global collection based on an identifying string.

The problem is that this code now will be running on a platform where the object referred to by someGlobalIdString will no longer be of type Register<uint32_t>, but instead Register<uint64_t>. This is a decision that must be made at runtime. Since I’m using templatized types I can’t have a single pointer that can point to either a Register<uint32_t> or a Register<uint64_t>. So I must either

  1. Have two copies of the class that imports this register, one that handles types of uint32_t and one that handles types of uint64_t. This solution obviously sucks because of the code duplication.
  2. Templatize the class that imports this register. In an ideal world this is probably the correct solution but it doesn’t really fit the “normal way of doing things” and the rest of the coworkers would probably prefer copy and paste over templatizing this type of class.
  3. Make an adapter. Subclass Register<uint64_t> to create a new class that accepts a Register<uint32_t> as a constructor and essentially just wraps that register and returns 64 bit values instead of 32. Rewrite the consuming class to always use the 64 bit version and when we’re on the platform that provides the 32 bit version just wrap it. The code segment above would look something like this:

The adapter:

class Reg32to64Adapter : public Register<uint64_t> { ... }

The consuming class:


Register* myReg; 
if( is32bitPlatform )
{
    Register* my32Reg = static_cast*>(importItemPtr(someGlobalIdString));
    myReg = new Reg32to64Adapter(my32Reg);
}else
{
    myReg = static_cast*>(importItemPtr(someGlobalIdString));
}

//Go on manipulating myReg

Is there a better solution out there? Some design pattern I don’t know about?

  • 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-24T21:22:51+00:00Added an answer on May 24, 2026 at 9:22 pm

    Try to use Bridge pattern where Implementor is a collection of common operations and specialization are ConcreteImplementors.

    http://en.wikipedia.org/wiki/Bridge_pattern

    Probably not best solution (overdesign), so please analyse it before use.

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

Sidebar

Related Questions

I currently working with PictureBox and facing one problem. First, I have drawn one
I'm currently working on a new Magento template, and I'm facing problems with jQuery.
I'm currently facing in problem using Core Data. I have two entities A and
I'm currently facing a strange problem in PHP. I have two scripts, index.php which
I'm currently facing a variable substitution related problem in groovy. While this is quite
I am currently working on a project and facing a problem with a task.
I'm currently working a lot with DDD, and I'm facing a problem when loading/operating
I'm facing a problem in C++ for which I currently don't have an elegant
Currently I am working with Oracle identity federation 10.1.4.0.1. I am facing one problem
I have developed a Silverlight website. The problem i am facing currently is when

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.