compilation error on function overloading..

This is a discussion on compilation error on function overloading.. within the C++ Programming forums, part of the General Programming Boards category; Hi All, Code: #include <iostream> #include <conio.h> using namespace std; class sample { int i,j; public: int myfunc(int); int myfunc(int,int); ...

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

    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
    Posts
    23,031
    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, 08: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, 09:18 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21