简体   繁体   中英

Scope issue in C++

I have following code:

#include <iostream>

using namespace std;

int main()
{
   addition(....);
}

constexpr static uint64_t addition (int a, int b) {
 .....
}

I get error as:

error: 'addition' was not declared in this scope

What is wrong here?

You try this:

#include <iostream>

using namespace std;

// function declaration
constexpr static uint64_t addition (int a, int b);

int main()
{
   addition(....);
}

constexpr static uint64_t addition (int a, int b) {
   .....
}

You need to declare the method before main() or you can define the complete method before main() .

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