Soldato
- Joined
- 23 May 2005
- Posts
- 2,964
- Location
- Auckland, New Zealand
ok need a little help here. I have two source code files with an array of objects (using the STL) declared in the main file and a function in main that says "use the source code in the other source file." I'd like to have a function that operates on the aray of objects inside the other source file. Normally this would just be a case of passing parameters of course. BUT this other source file is ONLY a C file, not C++. It is compiled using a parser generator that only compiles C code.
now, I set up the following files:
parser generated file:
function header file:
function body file (.cpp):
main .cpp file:
but it cannot identify "nameofarray" as it says it not declared yet (function source being compiled before main global declaration?)
compiler returns: funcs.cpp(4) : error C2065: 'nameofarray' : undeclared identifier
Is there any way of passing "nameofarray" into operation(); without passing it from main and through parse (not a possibility, not my function I'm using yacc (yet another compiler compiler)) and through function();? basically keeping all cpp code away from the parser generated file?
cheers for any help
now, I set up the following files:
parser generated file:
Code:
#include funcs.h
blah blah blah..
function();
function header file:
Code:
#includes for everything i need..
void function();
operation(ObjectArray &array);
function body file (.cpp):
Code:
#include funcs.h
void function(){
operation(nameofarray);
}
void operation(ObjectArray &array){
array = ObjectArray(x,y); //initialise the array
}
main .cpp file:
Code:
#include funcs.h
#includes
/*global space*/
ObjectArray nameofarray;
main{
...
...
Parse(); //uses the parser generated source file
}
but it cannot identify "nameofarray" as it says it not declared yet (function source being compiled before main global declaration?)
compiler returns: funcs.cpp(4) : error C2065: 'nameofarray' : undeclared identifier
Is there any way of passing "nameofarray" into operation(); without passing it from main and through parse (not a possibility, not my function I'm using yacc (yet another compiler compiler)) and through function();? basically keeping all cpp code away from the parser generated file?
cheers for any help

Last edited: