• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Another question, acessing functions

## Recommended Posts

I''ve been haveing trouble accessing some functions, I want to use some that are not in the same file (I''m using visual c++ in a workspace). the function is declared in a header that both files use, and its not under anything, like a struct or class. The error I''m getting is that its a undeclared identifier. Any help would be apperciated. Thank you, One-Winged Angel

##### Share on other sites
Hmm, have you tried putting extern before it in the header? I''ve never had any problems with functions, but I had a similar problem with global variables and that fixed it.

-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

##### Share on other sites
I think I might not have explained it right, the function I want to use is in one file and I want to use it in another, its just declared in the header. I put extern in front of it and it didn''t work, thx for the help anyways.

##### Share on other sites
If there is a header file with the function prototype in (eg. void MyFunction(int param1, int param2); ) then it should work fine. Check you didn''t make a mistake with the function prototype in the header.

By the way, I''m not sure if you''re making this mistake or not, but you shouldn''t define whole functions in header files, since that means they''ll get compiled once for each code file. You basically want functions defined in one single code file, and others use it through seeing the prototype in the header.

##### Share on other sites
I don''t know why I didn''t realize this before and mention it, the place where I''m trying to call the other function is from a function inside a struct, kinda like this:

fn I want
..
..
struct...
___fn im in...

I am very sorry about not explaining it right before, I''m kinda new to C++, if you couldn''t figure that out already.

##### Share on other sites
That last point makes no difference, by the way.

##### Share on other sites
Try to write your prototype at the beginning of your file were you need it.

like:
// a.cpp
void Function(int a)
{
}

// b.cpp
void Function(int a);

...

Funtion( 0 );

If it''s work maybe your include is wrong or maybe your prototype is hibe by some #if #endif

Why English rules?? C pas très malin tout ça!

##### Share on other sites
well I tried what you guys said, and nothing works.
I evan tried coping the function i need into the same area. well if any of you that are not busy, and have vc++ can take a look at the code if you email me at demonicraptor@hotmail.com.
Thanks for trying to help!

##### Share on other sites
Ok, it sounds like you''re making a fundamental mistake then. Can you show us:

a) The line of code that calls the function.
b) The line of code that includes the header file for the function
c) The line of code in the header file that is the function prototype.
d) The exact error from MSVC when you try to compile it.

That should be all we need.

##### Share on other sites
this in in game.cpp

in the game.cpp and mastermain.cpp

error: c:\my programs\other\game.cpp(189) : error C2065: ''laodmap'' : undeclared identifier

Just incase, here is the the fn I want to call:
{
ZeroMemory(&level,sizeof(level)); // clear level structure
ifstream fin(filename,ios::binary);
fin.close();
}

this is in mastermain.cpp

##### Share on other sites
Did you actually copy and paste all of this: because I''m guessing you didn''t.

This is what you claim to have written:
call fn:   loadmap("map0.mrpg");

But this is the error that looks like it was copied from MSVC:
error:   c:\my programs\other\game.cpp(189) : error C2065: ''laodmap'' : undeclared identifier

Notice the misspelling of ''loadmap'' as ''laodmap''. I bet you typed laodmap in game.cpp. Check it.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627657
• Total Posts
2978466

• 10
• 12
• 22
• 13
• 33