2

I am using netbeans IDE for my C++ implementation. I have two source files main.cpp and univ.cpp. And i defined a function show() in univ.cpp. How can i call this function from main. When i call normally like below, i get "show() not in scope".

    int main(int argc, char**argv)
    {
       show();
       return 0;
    }

I don't want to use a separate header file and define the function. Instead i want to define this function in cpp source file like stated above.

Thanks.

Ram Kumar
  • 91
  • 1
  • 1
  • 4

2 Answers2

2

You should create a header for univ called univ.h here would be the code:

#ifndef _UNIV_H_
#define _UNIV_H_

void show();

#endif

The you will need to include it in both cpp files.

#include <univ.h>
Dan
  • 1,874
  • 1
  • 16
  • 21
1

Declare the function:

int main(int argc, char **argv)
{
   extern void show();
   show();
}
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084