Thread: template

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    india
    Posts
    28
    Rep Power
    0

    Smile template


    No i actually want a template class defenition for me to understand the usage of template class
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Code:
    #include<iostream>
    #include<iomanip>
    
    using namespace std;
    
    template<typename T>class Number
    {
    public:
    	Number(T aNumber)
    	{
    		count = aNumber;
    	}
    
    	void SetCount(T aNumber)
    	{
    		count = aNumber;
    	}
    
    	T GetCount(void)
    	{
    		return count;
    	}
    
    private:
    	T count;
    };
    
    int main()
    {	
    	Number<int> i(5);
    	Number<double> d(10.5);
    
    	cout<<setprecision(2)<<fixed;
    	cout<<i.GetCount()<<" "<<d .GetCount()<<endl;
    
    	i.SetCount(1);
    	d.SetCount(2.0);
    
    	cout<<i.GetCount()<<" "<<d.GetCount()<<endl;
    
    
    	return 0;
    
    }
    Last edited by 7stud; August 12th, 2003 at 12:07 AM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    india
    Posts
    28
    Rep Power
    0

    Talking thanx


    thanx but i want internal implementation

IMN logo majestic logo threadwatch logo seochat tools logo