Typeid and Templates

This is a discussion on Typeid and Templates within the C++ Programming forums, part of the General Programming Boards category; Is there any way whatsoever to use typeid in a template? I want to use typeid(classname).name(); and store that in ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    Typeid and Templates

    Is there any way whatsoever to use typeid in a template? I want to use typeid(classname).name(); and store that in a string, but I can't handle for a class I don't know of unless I can use that string in a template.


    Is there any way to use something like

    template<typeid(classname)>?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    No.

    What are you trying to do? If you post more details on the code you're trying to write, perhaps we can help come up with an alternate design that will do what you want.

    gg

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Templates AND operator overloads

    I'm trying to make a universal data type using void poiners... it was a lazy way out... I'll use strcmp on the typeid(type).name() part. And to make sure the data type is defined, I'll use a #ifdef and #endif... so thats done.

    Thats a simplified version, but I need to know if you can use a template on an operator overload... it doesn't seem to think that that is code.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    give your compiler a boost and take a look at the any type by Kevlin Henney.
    Last edited by Stoned_Coder; 04-08-2003 at 10:42 AM.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    will it work with VC++?

    Also, how does it work? I was trying to write my own version.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Originally posted by Stoned_Coder
    give your compiler a boost
    Gotta love SC and the proverbial line. It's humorous every time.

    On a more serious note, boost is definately a good place to look.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Originally posted by Trauts
    Templates AND operator overloads

    I'm trying to make a universal data type using void poiners... it was a lazy way out... I'll use strcmp on the typeid(type).name() part. And to make sure the data type is defined, I'll use a #ifdef and #endif... so thats done.

    Thats a simplified version, but I need to know if you can use a template on an operator overload... it doesn't seem to think that that is code.
    I can't use that, so I have to get a version I write working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. templates and typeid
    By l2u in forum C++ Programming
    Replies: 14
    Last Post: 08-29-2007, 07:55 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21