Library idea... is it possible to do?

This is a discussion on Library idea... is it possible to do? within the C++ Programming forums, part of the General Programming Boards category; I don't know exactly how libraries work, but'd be extremely nice to be able to use this: template <typename Type1="int"> ...

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

    Library idea... is it possible to do?

    I don't know exactly how libraries work, but'd be extremely nice to be able to use this:

    template <typename Type1="int">

    because then you could use typeid(type).name() and use that as a template, hence being able to get the type back!

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Can you go into detail? I know about the RTTI but my experience in templates is limited. Why would this be a good thing?

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Say you're working on a variant type.

    I've been modifying the Boost Any one.

    Anyway, you can't get back.... you can use typeid(type) to get the type, or typeid(type).name() to get it as a string, but you cannot use the type_info class or the character array in very many ways...

    so you have to cast when you want the data back, for the Any type, like this:

    cout << any_cast<int> (any1) << endl;

    While if you could do that, you could just have

    cout << any1 << endl;

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    go here and download Loki. Look at its TypeInfo class.
    btw for template classes you are allowed to specify default parameters tho it would be int not "int"
    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
    I know, but it was an example so that you could pass a string in case you used typeid.

    where on the site is it?

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I just found it... it doesn't look like it does what I meant

    btw for template classes you are allowed to specify default parameters tho it would be int not "int"
    I meant a string intentionally. I know you can do default parameters, but I want to be able to use a string in it... that way you could get the datatype back from typeid(type).name()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 05:52 AM
  2. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  3. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 08:55 AM
  4. Exception idea in C compatible library. Comments.
    By anonytmouse in forum Windows Programming
    Replies: 2
    Last Post: 10-31-2003, 09:11 AM
  5. Replies: 4
    Last Post: 11-12-2002, 06:26 AM

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