Thread: Data type checking?

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

    Data type checking?

    Is there any easy way to know what data type is being used? I have a class that I'm using templates with, and I want it to have different functions if it is an integer or a float.

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    5
    Hi
    I think you need to specialize your whole template class. It´s called explicit instantiation. Search for this if you want to know more about it.
    My suggestion i something like this:
    [code]
    //I suppose you have something like this.
    template <class Type>
    class Myclass
    {
    ... member,functions etc
    };

    //You will have to specialize your class by adding this
    template <> class MyClass<int>
    {
    ....members,funtions for int etc
    };
    //and this
    template <> class MyClass<float>
    {
    ....members,funtions for float etc
    };
    [\code]

    Hope this helps a bit.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    ah, so there's no easy way when you overload every single existing operator? the difference would be atoi versus atol or atof

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM