2 questions

This is a discussion on 2 questions within the C++ Programming forums, part of the General Programming Boards category; im really new to c++, i started last week... i wonder how to run a fnunction. i mean if i ...

  1. #1
    myUserName
    Guest

    Question 2 questions

    im really new to c++, i started last week... i wonder how to run a fnunction. i mean if i have a function named like
    <
    int myFunction()
    {

    cout<<"A function";

    }
    >

    how do i run it?

    and how do i make a windows application???

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    You need to call it in main(); take a look at the tutorials on this site for some basics.
    Windows programming is a very complex API, and I would suggest you get down C++ pretty well before starting.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    okay, for fxns, you may want to consult the tutorials and faq for it.

    same thing with windows programming, windows programming forum, google, and FAQ.

    if you are new to c++, have you had programming experience before, I'm inclined to believe no because you are wondering how to call a fxn. if you are new to programming in general, you would want to learn concepts and other things before thinking about win32api and games.

    but for a fxn, ex. a fxn to cout something would be like the following:

    Code:
    void function() {
        std::cout << "A function" << std::endl;
    }
    int main() {
        function();
        return 0;
    }

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    for very very short functions use "inline" it makes it go faster...but you cant tell the difference because instead of calling the function it places the body of the function in where it is being called....hehe
    nextus, the samurai warrior

  5. #5
    myUserName
    Guest
    Well ive programmed in javascript before, but im not an expert.. ive tried writing

    <code>

    #include <iostream>

    int main()
    {

    function();

    }

    int function()
    {

    }
    </code> but it doesnt work... maybe i just forgot that semicolon

  6. #6
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Problem here is that the compiler has never heard of your function before you call it in main.

    Put

    int function();

    above main and see if that works.

  7. #7
    myUserName
    Guest
    Okay ive tried the following code:

    Code:
    <code>
    
    #include <iostream>
    
    int main()
    {
    
      function();
    
      return 0;
    }
    
    int function()
    {
    
      std::cout << "A function" << std::endl;
    
    
      return 0;
    }
    
    </code>
    im using dev-c++4 and it says "implicit declaration of function 'int function(...)'"

  8. #8
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Code:
    #include <iostream>
    
    int function ();
    
    int main()
    {
    
      function();
    
      return 0;
    }
    
    int function()
    {
    
      std::cout << "A function" << std::endl;
    
    
      return 0;
    }
    Try that

  9. #9
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    power to non-prototyped functions!

    Code:
    #include <iostream>
    
    int function()
    {
    
      std::cout << "A function" << std::endl;
    
    
      return 0;
    }
    
    int main()
    {
    
      function();
    
      return 0;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you either have to prototype the fxn or place the whole fxn above main. fxns can only see what is above them.

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    1
    I am ok at C++... I made a VERY simple program to let you see how some basic things work, if you already don't know how. I havent error checked it yet, and I know that the char does not work but you get the idea.
    Attached Files Attached Files
    Last edited by xzozx; 02-19-2003 at 08:54 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

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