Mandroid
Mandroid

Reputation: 7468

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?

Upvotes: 0

Views: 60

Answers (1)

Nitin Bisht
Nitin Bisht

Reputation: 5331

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().

Upvotes: 3

Related Questions