title: Function Overloading in Visual c++
body: <p>I was writing a program of function overloading in Visual C++ 2010 .
  Following is my code</p>
  
  <pre><code>// overload.cpp : Defines the entry point for the console application.
  
  #include&lt;Windows.h&gt;
  #include&lt;iostream&gt;
  #include&lt;conio.h&gt;
  
  using namespace std;
  
  //abs is overloaded in 3 types
  int abs(int i);
  double abs(double d);
  long abs(long  f);
  
  void main()
  {
      cout&lt;&lt;abs(-10)&lt;&lt;"\n";
      cout&lt;&lt;abs(-11.0)&lt;&lt;"\n";
      cout&lt;&lt;abs(-9L)&lt;&lt;"\n";
      getch();
  }
  int abs(int i)
  {
      cout&lt;&lt;"using integer abs()\n";
      return i&gt;0? -i:i;
  }
  double abs(double d)
  {
      cout&lt;&lt;"using double abs()\n";
      return d&gt;0? -d:d;
  }
  long abs (long l)
  {
      cout&lt;&lt;"using long abs()\n";
      return l&gt;0?-l:l;
  }
  </code></pre>
  
  <p>I am having problems in double abs and long abs function that </p>
  
  <pre><code>1&gt;c:\users\abc\documents\visual studio 2010\projects\overload\overload\overload.cpp(22): error C2084: function 'double abs(double)' already has a body
  1&gt;c:\users\abc\documents\visual studio 2010\projects\overload\overload\overload.cpp(26): error C2084: function 'long abs(long)' already has a body
  </code></pre>
  
  <p>Why this problem is coming?
  I have changed the  compilation from c to c++
  <strong>but recently I ran an other program for overloading,it worked.I don't know how? here is the code.</strong> </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdio&gt;
  #include&lt;conio.h&gt;
  #include&lt;cstring&gt;
  using namespace std;
  void stradd(char*s1,char*s2);
  void stradd(char*s1,int i);
  void main()
  {
      char str[80];
      strcpy(str,"hello");
      stradd(str,"there");
      cout&lt;&lt;str&lt;&lt;"\n";
      getch();
  }
  //concatenate a string with a "stringized "integer
  void stradd(char*s1,int i)
  {
      char temp[80];
      sprintf(temp,"%d",i);
      strcat(s1,temp);
  }
  //concatenate 2 strings
  void stradd(char*s1,char *s2)
  {
      strcat(s1,s2);
  }
  </code></pre>
  
  <p>and output is hellothere</p>