about function overloading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rawinder dhillon
    New Member
    • Oct 2006
    • 8

    about function overloading

    hi its rawinder dhillon
    could you please tell me the strog points (advantages) of [B]function overloading.
    and also tell me the same for operators NEW and DELETE
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by rawinder dhillon
    hi its rawinder dhillon
    could you please tell me the strog points (advantages) of [B]function overloading.
    and also tell me the same for operators NEW and DELETE
    overloading allows objects to perform the same action differently depending on its environment.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      use new to create new objects. It calls the objects' constructor.
      In c++ use delete to remove objects from memory in the object's destructor. Typically used for garbage collection.

      Comment

      • anaphaxeon
        New Member
        • Oct 2006
        • 30

        #4
        oooh function overloading. This should work to explain.

        public int Add(int int1, int int2)
        {
        return int1+int2;
        }
        public int Add(double dbl1, double dbl2)
        {
        return dbl1+dbl2;
        }

        this gets even better if you are returning general objects instead of Type-specific data. For example.

        public object Add(int int1, int int2)
        {
        return (object)(int1+i nt2);
        }
        public object Add(string str1, string str2)
        {
        return (object)(str1+s tr2);
        }

        this means I can do this,

        string myName = (string)Add("Jo hn","Smith");
        int myAge = (int)Add(10,8);
        string nameAndAge = (string)Add(myN ame,myAge.ToStr ing());


        function overloading is cool, but in c# we can take overloading a little higher, operator overloading. Now we can overload =, or >, or <, operations performed on our class with our own comparison operations.

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Hi there,

          welcome to thescripts, take care my fren.. :)

          Comment

          Working...