class template Convert which can convert itself to any data type
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: class template Convert which can convert itself to any data type

Threaded View

  1. #1
    Join Date
    Mar 2011
    Location
    Washington D.C.
    Posts
    41

    class template Convert which can convert itself to any data type

    Code:
    template<class T>
    class Convert
    {   
       T data;
    public: 
       Convert(const T& tData = T()) : data(tData)
       { }
    
       template<class C>   
       bool IsEqualTo( const C& other ) const      
       {        
           return data == other;   
       }
    };
    Code:
    template<class T>
    operator T() const
    {
        return data;
    } 
    
    Convert<int> IntData(40);
    float FloatData;
    double DoubleData;
    
    FloatData = IntData;
    DoubleData = IntData;
    Code:
    Convert<int>::operator<float> float();
    Convert<int>::operator<double> double();
    ) ----------------------------------------------------
    Why do we use operator? Is float and double function names below?
    Code:
    Convert<int>::operator<float> float();
    Convert<int>::operator<double> double();
    Thanks in advance
    Last edited by loves_oi; September 23rd, 2012 at 07:54 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center