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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:41:51+00:00 2026-06-02T02:41:51+00:00

If I have a variable whose type was a templated class, and I want

  • 0

If I have a variable whose type was a templated class, and I want to build another variable of a different templated class, but use the same template parameter, how could I?

While the example below does not work, it hopefully gives the idea of what I am looking to accomplish. If there is no very specific way to do this, is there a way to have some sort of a lookup table design pattern to do this? There is only six or so different templated types I will probably end up using.

template<typename T>
class A{
public:
    typedef T Type;
};

template<typename T>
class B{};

int main(void){
    A<int> var1;

    B<var1::Type> var2;
}

My apologies if this is a duplicate question, but I did not see anything like this asked before.

EDIT

I would like a way for this to work with Visual Studio 2010 AND gcc, without using a third party library. So not all C++ 11 features may be supported.

Also, without using a typedef A<int> or knowing A<int> as this code is simply a test case scenario to show basic functionality of what I want. I want a way to get the template type from the variable whose type was a template.

  • 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-06-02T02:41:53+00:00Added an answer on June 2, 2026 at 2:41 am

    Even with VC++ 2010’s pre-standardized decltype, I think you might be able to do something like this:

    template<typename T>
    struct A {
        typedef T Type;
        Type foo();
    };
    
    template<typename T>
    struct B {};
    
    int main() {
        A<int> var1;
        B<decltype(var1.foo())> var2;
    }
    

    This depends on being able to form some expression that uses the type you want.

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

Sidebar

Related Questions

I can get all those url's whose content/type is text/html, but If I want
I have an integer variable ( time ) in one view controller whose value
i have variable $lang which convert string to the selected language but i am
I have a variable foo that contains a time, lets say 4pm today, but
I have a variable that im define with another variable and some text. $title
i have made a file open dialog, it contains an edit control whose variable
Does Java have the possibility of anonymous enums? For example, I want my class
Want to verify that my understanding of how this works. Have a C++ Class
I have created this datastructure: class Event { public: Event(EVENT_TYPE type, void* pSender =
Let's say I have a type of lookup table which I can build for

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.