Thread: expl...

  1. #1
    Registered User
    Join Date
    Jun 2003

    Question expl...

    Can anyone please explain to me why this program doesn't work ->
    #include <iostream>
    using namespace std;
    double functone(int x, int y);
    double functtwo(int a, int b);
    int main()
    	int num, num2;
    	cout << "LIL' TESTING PROGRAM.";
    	cout << endl << endl;
    	cout << "Enter two number:";
    	cin >> num >> num2;
    	cout << "Sum is " << functone(num,num2) << endl;
    	cout << "Mult is " << functtwo(num,num2) << endl;
    	cout << endl;
    	return 0;
    functone(int x,int y)
    	return (x + y);
    functtwo(int a,int b)
    	return (a * b);
    I'll also like to know what the compiler means by -> error C2556: 'int __cdecl functone(int,int)' : overloaded function differs only by return type from 'double __cdecl functone(int,int)'
    C:\Documents and Settings\User\Desktop\example\f_testrun.cpp(4) : see declaration of 'functone'

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You forgot the word 'double' at the start of the implementation of your functions.

    At present, the compiler defaults them to returning int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001

    Compiler error messages in general...

    You can look-up the error number in your compiler's documentation for a brief explanation.

    But, the compiler doesn't know what you were trying to do... So, sometimes the error message isn't very helpful. For example, in this case you were not trying to overload a function. (If you know what overloading is... that would tell you that "something didn't match".)

    The compiler will usually indicate the line number with the actual problem. Sometimes it's the line above. Sometimes it's somewhere else. (Maybe the function prototype is wrong, but the compiler thinks it's the compiler definition.. because they dont' match.)

    Some errors, such as a mis-placed curly-bracket, can cause the compiler to report hundreds of errors! (If your program has that many lines of code.)

    Usually, you just have to carefully check the code on (or near) the suspect line and find the exact error yourself.

    Link errors can be more difficult to find than compile errors, because the line-numbers are not referenced. (The line-numbers in the obj file are different from the cpp file.)

    If you write a few lines of code, test-compile and test-run... write a few more lines of code and test...etc., it will be easier to find and fix your bugs.

  4. #4
    Registered User
    Join Date
    Jun 2003


    Thankz alot..
    Now i have a better understandig of the matter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expl c lib
    By Nutshell in forum A Brief History of
    Replies: 0
    Last Post: 04-07-2002, 12:26 AM