Another question, acessing functions
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
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^_^)
-Deku-chan
DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)
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.
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.
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.
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.
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.
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!
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!
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!
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!
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.
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.
call fn: loadmap("map0.mrpg");
this in in game.cpp
header file including: #include "thehead.h"
in the game.cpp and mastermain.cpp
what header file says:void loadmap(char* filename);
in the thehead.h
error: c:\my programs\other\game.cpp(189) : error C2065: ''laodmap'' : undeclared identifier
Just incase, here is the the fn I want to call:
// load up a map
void loadmap(char* filename)
{
ZeroMemory(&level,sizeof(level)); // clear level structure
ifstream fin(filename,ios::binary);
fin.read((char*)&level,sizeof(level));
fin.close();
}
this is in mastermain.cpp
this in in game.cpp
header file including: #include "thehead.h"
in the game.cpp and mastermain.cpp
what header file says:void loadmap(char* filename);
in the thehead.h
error: c:\my programs\other\game.cpp(189) : error C2065: ''laodmap'' : undeclared identifier
Just incase, here is the the fn I want to call:
// load up a map
void loadmap(char* filename)
{
ZeroMemory(&level,sizeof(level)); // clear level structure
ifstream fin(filename,ios::binary);
fin.read((char*)&level,sizeof(level));
fin.close();
}
this is in mastermain.cpp
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement