Defining the error of function declaration and the problems caused by function mutual invocation

Source: Internet
Author: User

We generally have a habit of writing programs, and writing functions like writing functions to the front of the main function,

Commonly used in the formulation:

#include <iostream>
using namespace std;
void A ()
{
    cout<< "function a\n";
}
void B ()
{
    cout<< "function b\n";
}
int main ()
{
    A ();
    B ();
    return 0;
}

Run Result:

It's normal to look right now, isn't it? The running result is also true, our general definition function is accustomed to write like this, thought that does not need to declare the function.

So now we look at this program changes after this source code is not still can do this? Without declaring it?

#include <iostream>
using namespace std;
void A ()
{
    cout<< "function a\n";
    B ();
}
void B ()
{
    cout<< "function b\n";
    A ();
}
int main ()
{
    A ();
    B ();
    return 0;
}

This program does not declare an error before declaring it, because there is no statement.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.