Why is my HelloWorld function not declared in this scope?

You need to either declare or define the function before you can use it. Otherwise, it doesn’t know that HelloWorld() exists as a function.

Add this before your main function:

void HelloWorld();

Alternatively, you can move the definition of HelloWorld() before your main():

#include <iostream>
using namespace std;

void HelloWorld()
{
  cout << "Hello, World" << endl;
}

int main()
{
  HelloWorld();
  return 0;
}

Leave a Comment