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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:48:44+00:00 2026-05-31T17:48:44+00:00

I have a legacy interface that gives me the type to instance under the

  • 0

I have a legacy interface that gives me the type to instance under the form of a string, for example “int”, “float”, etc.

I’ve came up with these two functions to solve the problem:

template <typename T>
T type_factory(const std::string& type_id)
{
    if (!type_id.compare("long"))
    {
        long res;
        return res;
    }

    if (!type_id.compare("double"))
    {
        double res;
        return res;
    }

    if (!type_id.compare("char"))
    {
        char res;
        return res;
    }
}

and

template <class PointerClass, typename T>
PointerClass<T>* pointer_factory(void* ptr, T dummy_type)
{
    return static_cast<PointerClass<T>*>(ptr);
}

//Desidered usage:
//void* raw_ptr;
//Calculator<int>* p = pointer_factory<Calculator>(raw_ptr, type_factory("int"));

The second function doesn’t compile the error is “expected unqualified-id” near PointerClass.

Could someone please tell me why the second function does not compile and how to fix it?

Thanks in advance.

  • 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-31T17:48:45+00:00Added an answer on May 31, 2026 at 5:48 pm

    Seems like you need a template template:

    template < template<typename T> class PointerClass, typename T>
    PointerClass<T>* pointer_factory(void* ptr, T dummy_type) 
    

    instead of

    template <class PointerClass, typename T>
    PointerClass<T>* pointer_factory(void* ptr, T dummy_type)
    

    since PointerClass is itself a template.

    This fixes the compilation error, you’ll have to test if it does what you want yourself, though I doubt it will.

    EDIT:

    Seems like a factory class, instead of templates, might be easier to write and understand by others in this case.

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

Sidebar

Related Questions

We have a legacy system that is essentially a glorified telnet interface. We cannot
I have a large chunk of legacy php code that I need to interface
I have legacy DB that store dates that means no-date as 9999-21-31, The column
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
We have some legacy code that needs to identify in the Page_Load which event
I have a legacy VB6 application that was built using MSDE. As many client's
I have a legacy 3rd party COM .dll that is used to provide an
I have somewhat of a problem. We have a centralized interface engine that will
I was looking through some legacy code we have and I noticed something that
I have a legacy database with a pretty evil design that I need to

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.