I’m new to CPP, and I want to know how to run a function that isn’t in its scope. I’m used to doing such things in javascript, and I get an error CPP when I try to do that. What I mean is the below:
#include <iostream>
using namespace std;
int tic_h;
int tic_v;
void echo(string e_val){
cout << e_val;
}
void c_mes(){
echo("X|0|X\n");
echo("-----\n");
echo("X|0|X\n");
echo("-----\n");
echo("X|0|X\n");
s_v();
}
void s_v(){
echo("Please enter vertical coordinate: ");
cin >> tic_v;
if(tic_v<4&&tic_v>0){
c_mes();
}else{
s_v();
}
}
void s_h(){
echo("Please enter horizontal coordinate: ");
cin >> tic_h;
if(tic_h<4&&tic_h>0){
s_v();
}else{
s_h();
}
}
int main(){
s_h();
return 0;
}
I get this error:
error: ‘sv’ was not declared in this scope on line 16
How can I make it work?
You should put a function prototype before using the function, for the compiler to know what it is going to be.
Put
Right after the
#includeline.