Thread: compilation error on function overloading..

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    145

    compilation error on function overloading..

    Hi All,

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    class sample
    {
          int i,j;
          public:
          int myfunc(int);
          int myfunc(int,int);
    }
    
    int sample::myfunc(int k)    // Following line  gives error
    {
            cout<<"val of one int: "<<k<<"\n";
            return 0;
    }
    
    int sample::myfunc(int k,int m)
    {
            cout<<"val of one int: "<<k+m<<"\n";
            return 0;
    }
    
    
    int main()
    {
        sample an;
        cout<<"value of single int: "<<an.myfunc(3,4)<<"\n";
        getch();
        return 0;    
    }



    Thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    18
    You are missing a semi-colon from after the closing brackets of your sample class

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Also,
    Code:
    class sample
    {
          int i,j;
          public:
          int myfunc(int k);
          int myfunc(int k,int m);
    };
    Don't remove the parameter names.
    SourceForge.net: Do not remove parameter names - cpwiki
    And k and m are hardly describing names. This isn't math, you know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive function
    By WatchTower in forum C Programming
    Replies: 11
    Last Post: 07-15-2009, 07:42 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM