简体   繁体   中英

functions shall not be declared at block scope

I couldn't able to understand the following misra rule, " functions shall not be declared at block scope " . the explanation given in the document is "A function declared at block scope will refer to a member of the enclosing namespace, and so the declaration should be explicitly placed at the namespace level." What they mean by will refer to member of enclosing namespace? Could someone clarify?

It means that when you have this, foo will have its definition outside of bar , in the namespace:

namespace {
    void bar() {
        void foo();
    }

    //could define foo here
}

What it's saying is to just move the declaration out to the same level as the definition:

namespace {
    void foo();

    void bar() {}

    //could define foo here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM