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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:27:03+00:00 2026-05-25T18:27:03+00:00

I want to be able to create a method in a templated class that

  • 0

I want to be able to create a method in a templated class that returns the name of the type subsituted in the template parameter.

eg:

template <typename T>
class CPropertyValueT 
{
  std::string GetTypeName()
  {
    return #T;
  }
}

This is possible with a preprocessor macro using #, I figured there must be a way with templates.

Is this possible?

  • 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-25T18:27:03+00:00Added an answer on May 25, 2026 at 6:27 pm

    You can use typeid(T).name(), though it will return decorated name of the type.

    If you’re using GCC, then you can use GCC API, declared incxxabi.h header, to demangle the names.

    Here is an example (source):

    #include <exception>
    #include <iostream>
    #include <cxxabi.h>
    
    struct empty { };
    
    template <typename T, int N>
      struct bar { };
    
    
    int main()
    {
      int     status;
      char   *realname;
    
      // exception classes not in <stdexcept>, thrown by the implementation
      // instead of the user
      std::bad_exception  e;
      realname = abi::__cxa_demangle(e.what(), 0, 0, &status);
      std::cout << e.what() << "\t=> " << realname << "\t: " << status << '\n';
      free(realname);
    
    
      // typeid
      bar<empty,17>          u;
      const std::type_info  &ti = typeid(u);
    
      realname = abi::__cxa_demangle(ti.name(), 0, 0, &status);
      std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n';
      free(realname);
    
      return 0;
    }
    

    Output:

      St13bad_exception       => std::bad_exception   : 0
      3barI5emptyLi17EE       => bar<empty, 17>       : 0
    

    Another interesting link that describe demangling in GCC and Microsoft VC++:

    • C++ Name Mangling/Demangling
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to create a class (in Python) that once initialized
In Delphi, I want to be able to create an private object that's associated
I want to be able to create a GUID/UUID on the iPhone and iPad.
I'm trying to create a webapplication where I want to be able to plug-in
I create a file in JavaScript. Now I want to be able to make
I want to be able to capture the exception that is thrown when a
I'm implementing a button class in cocos2d, and I want to be able to
I would like to create a base class that will be inherited by other
I would like to create a class that describes a file resource and then
I want to be able to do: For Each thing In things End 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.