简体   繁体   中英

Calling function in a C++ source file from main

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.

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>

Declare the function:

int main(int argc, char **argv)
{
   extern void show();
   show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM