functions

This is a discussion on functions within the C++ Programming forums, part of the General Programming Boards category; hey sorry to bother every1 im fairlynew to c++ and im slightly stuck i have declared 2 fucntions and they ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    functions

    hey sorry to bother every1
    im fairlynew to c++ and im slightly stuck
    i have declared 2 fucntions and they work fine however i am now at the stage where i need to call each fucntion from within the other like this:
    void fucntion1(){
    function2;
    }

    void fucntion2(){
    function1;
    }
    of course it is slightly more complicated than that but i get the error undeclared identifier is there anyway to get fucntions like the above to work
    thanks for ur time
    pants

  2. #2
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    call the function using function1() .... its that simple

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    And also make sure you actually spell the function name correctly.

  4. #4
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    void function1(); //must say "hey i HAVE declared this function"
    void function2();

    void function1() // function declaration
    {
    // your code
    }

    void function2()
    {
    //your code
    }
    /*
    nothin to it
    also see:

    http://www.cprogramming.com/tutorial/lesson4.html
    Last edited by Nor; 03-19-2002 at 12:05 PM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    22
    yeah i thougt it would have been that easy but for soem reason it keeps sayin that the seocnd function is an undelcarded identifier



    int main(){

    fucntion1();
    return 0;

    }
    void fucntion1(){
    cout<<"helllo";
    }


    i tried this to but it says 2 errors
    1)'fucntion1' : undeclared identifier
    2)'fucntion1' : redefinition; different type modifiers
    any ideas???
    cheers pants

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Follow Nor's advice - use a function prototype

    #include <iostream>

    void fucntion1(); //This is a function prototype.

    int main(){

    fucntion1();
    return 0;

    }
    void fucntion1(){
    cout<<"helllo";
    }

  7. #7
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    /*-----Start Cut-------------*/

    //Must declare a function before you can use it

    #include <iostream>
    void function1();

    int main(){

    fucntion1();
    return 0;

    }

    void fucntion1(){
    cout<<"helllo";
    }
    /*---Stop Cut------------------*/
    you only have to declear a function if you use it before you define it

    let me know if this doesn't work.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    22
    thats brill it works
    didnt realise that u could do that
    thanks alot
    pants

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM

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