function scope

C

carmelo

Hi, I wrote a program in c++ and it works. now i want to put all the
code in 1 file and leave in the main.cpp only a few things. In the
main I call a function that is in the other file but it doesn't work.
I tryed to declare the function extern, I tried to include an header
with the declaration, but the problem is always the same, error C2129:
static function 'void display(void)' declared but not defined. What
can I do?
 
J

jason.cipriani

(e-mail address removed)...
Hi, I wrote a program in c++ and it works. now i want to put all the
code in 1 file and leave in the main.cpp only a few things. In the
main I call a function that is in the other file but it doesn't work.
I tryed to declare the function extern, I tried to include an header
with the declaration, but the problem is always the same, error C2129:
static function 'void display(void)' declared but not defined. What
can I do?

When you declare/define a function as "static", that function is only
in scope in the file it is declared/defined in (and it is not exported
from that translation unit either). Don't declare it as static.

In the file you want to use display() in, declare it simply as:

void display (void);

And in the file that defines display, define it just like:

void display (void) {
// your code
}

The "extern" is implied on function declarations.

If you start using your display() function in more than one other
source file, eventually it becomes convenient to just stick the
declarations in a header file and #include that header in all the
source files you want to use display() in.

Jason
 
C

carmelo

(e-mail address removed)...


When you declare/define a function as "static", that function is only
in scope in the file it is declared/defined in (and it is not exported
from that translation unit either). Don't declare it as static.

In the file you want to use display() in, declare it simply as:

void display (void);

And in the file that defines display, define it just like:

void display (void) {
// your code

}

The "extern" is implied on function declarations.

If you start using your display() function in more than one other
source file, eventually it becomes convenient to just stick the
declarations in a header file and #include that header in all the
source files you want to use display() in.

Jason


Thank you sooooooooooo much Jason! Now It works!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top