Q: Member function of templated class I am new to templates and i have some troube understanding this piece of code
template <typename T>
class Item
{
  T data;
  public:
   Item <T> ():data(T())
   { 
     cout<<"inside constructor for Item class"<<endl;}
     void setdata(T nvalue){
     data=nvalue;
   }
      Item <T> operator +(int s){
      return Item <T> (data + s);
   }
      T getdata() const
      {
        //T temp =data[0];
         return data;
         }
     void printdata()
      {
       cout<<data<<endl;
      }
};

The part which i don't understand is the function
Item <T> operator +(int s){
  return Item <T> (data + s);
} 

I understand that operator '+' is being overloaded here but i don't understand what is the function of Item <T> in the return statement and before operator + (int s) 

A: Lets say you have this code:
Item<int> myItem;

Item<int> myItem2 = myItem + 3;

This will create and instance of the template (this is different from a instance of a class)
Note: there was an error in your original code, you are missing the declaration of a consutrctor:
Item <T> (T num):data(num)
{ 
  cout<<"inside constructor for Item class"<<endl;
}

This will look like this:
class Item
{
    int data;
    public:
        Item <int> (int num):data(num)
        { 
            cout<<"inside constructor for Item class"<<endl;
        }

        Item <int> ():data(int())
        { 
            cout<<"inside constructor for Item class"<<endl;
        }

        void setdata(int nvalue)
        {
            data=nvalue;
        }

        Item<int> operator +(int s)
        {
            return Item <int> (data + s);
        }

        int getdata() const
        {
           return data;
        }

        void printdata()
        {
           cout<<data<<endl;
        }
};

Btw this class will only work if T can be added with an int.
Item<int> myItem2 = myItem + 3;

The result of  

myItem + 3

Will be a new Item that presumably now contains the value data from myItem plus 3 (myItem2);
