C++ Beginner. Adding a function and calling it fails -


can me , let me know why failing? getting error shown below:

#include "stdafx.h" #include <string> #include <iostream> using namespace std; #include <conio.h>  int main() {     int a;     string abc = "";     cout << "enter name\n";     cin >> abc;     cout << "enter age\n";     cin >> a;     cout << "hello " << abc << ", nice meet you.\n";      startpause();      return 0; }  void startpause() {     cout << "\npress key continue..." << endl;     _getch(); } 

severity code description project file line suppression state error c3861 'startpause': identifier not found greetingsconsoleapp \bpm-fs103\users...\greetingsconsoleapp.cpp 20

the compiler processes compilation unit, .cpp file in case, sequentially top bottom.

your startpause function has been neither declared nor defined time compiler finds call it, complains. it's analogous having undeclared variable.

to solve it, either:

  1. add forward function declaration before definition of main, or
  2. move definition of main it's @ bottom of compilation unit

in other words, either this:

// includes , stuff...  void startpause();  // <-- forward declaration  int main() {     // body definition }  void startpause() {     // body definition } 

or this:

// includes , stuff...  void startpause() {     // body definition }  int main() {     // body definition } 

any of these 2 solve problem because compiler know startpause before invocation attempt made , know do.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -