Thread: Problem with defining function

  1. #16
    Registered User ITAmember's Avatar
    Join Date
    Mar 2009
    Location
    Nebraska
    Posts
    72
    Quote Originally Posted by curious View Post
    ok the basic structure is :
    Code:
    #define ......
    
    int main()
    {
    }
    
    bool func() /**bool is taken care of and works fine**/
    {
    
       defined function is called here as explained above
    }
    You need to add a function prototype for bool func() before you call it from main, if that's what you're doing. Like this:

    Code:
    #define ......
    
    /*function prototype*/
    bool func();
    
    int main()
    {
    }
    
    bool func() /**bool is taken care of and works fine**/
    {
    
       defined function is called here as explained above
    }
    EDIT:

    Say you have the code

    Code:
    int main()
    {
        a();
    }
    
    void a()
    {
        /* do something */
    }
    Now, the compiler is going to go along like this

    Ok here's the main function, I'll just dive into it and start compiling the code in there. Hmm, "a();", I've never seen "a" before, what's it supposed to be? Wait, you're calling it? Does that mean it's a function? Could it be a typo? For that matter, it's not even supposed to exist! I guess I'll just have to throw an error as I'm not smart enough to look ahead.

    Hope that clears the function prototype issue up if that is a problem, I'm not sure exactly what the problem is.
    Last edited by ITAmember; 06-01-2009 at 09:28 PM.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by curious View Post
    @tabstop :defined it but it didn't work
    Show us.

  3. #18
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by curious View Post
    ok here's what i have done;

    #define a(r) ((4)*(1/r)*(1-(1/r)));

    using it like this:

    tot = tot + a(r);

    But while compiling i get :

    invalid operands to binary +

    Can anyone suggest me what am i doing wrong?
    What are you returning from the func() function? I guess the problem is with bool type returning.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  2. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  3. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM