PickyBiker:
I created a file-2.h for the foo definition and put the actual foo function in the .cpp file. Now the obj1 appears to be undeclared.
First:
I apologize for the bad comment. In foo.cpp, 'obj1' is not a global. It's local to that file (but visible to all functions in that .cpp file).
Also, note that 'obj1' is an instance of the class LOW_LEVEL, which you've defined in low_level.h. Therefore, it only knows of public functions from that class (namely writeCommand). This means you should not be using the dot-operator to call foo(). You can, however, call "obj1.writeCommand()" is a correct use of the invocation (dot) operator.
Second:
The function foo(), declared in foo.h and defined in foo.cpp is not a class member function (functions declared in a class are called class member function). It is a regular function, one that you otherwise could have defined in the file containing main(). Once you #include the header file in which the function appears, calling the function is sufficient.
Third:
If you want to use a LOWER_LEVEL object that's defined in another file, you must declare it as "extern" and make sure that it is defined in that other file.
Sketch:
#include "low_level.h"
#include "file_2.h"
extern LOW_LEVEL obj1; //"extern" is used to refer to the fact that obj1 is defined externally (outside)
//of this file, namely, in file_2.cpp
LOW_LEVEL LL;
void setup()
{
}
void loop()
{
u8 cmd[10];
u8 cCount = 5;
LL.writeCommand(cmd, cCount);
obj1.writeCommand(cmd, cCount);
foo(cmd, cCount); //foo() is not a member function of the LOWER_LEVEL class!
}
file_2.h
#include "low_level.h"
#ifndef FILE_2_H
#define FILE_2_H
extern LOW_LEVEL obj1; //This is a declaration. Any file that #include file_2.h will know of obj1.
void foo(u8* cmd, u8 cCount);
#endif
file_2.cpp
//#include "low_level.h" //Unnecessary since you've #included it in file_2.h
#include "file_2.h"
LOW_LEVEL obj1; //Definition of obj1.
void foo(u8* cmd, u8 cCount)
{
obj1.writeCommand(cmd, cCount); //Using object 'obj1', which has global scope.
}