Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years ago.
referencing a library from another library
I have 2 library's, 1 is the RA8875 and the other is one im creating. I have alot of code which I dont want in the main program (hense putting it into a library) But I need to access the RA8875 library from my library and the main program. This causes a problem as I dont want to initalise it from 2 areas as it could cause problems.
How do I send the reference of the RA8875 library which has been declared in the main program to the library im making so that I can call functions from both places?
I have seen this: https://developer.mbed.org/forum/mbed/topic/2854/
but I cant see how it applies to another library. I understand how it works in the same file but im trying to do it across files. I have tried it and it keeps asking me to put a declaration in like its a second lcd screen.
1 Answer
10 years ago.
It works the same for libraries (the example there also shown the Serial library being passed around).
So probably in your constructor you add the requirement for a pointer to an RA8875 instantiation being included. And this you can use to call all your functions. One of your private/protected variable is a pointer to an RA8875, and in the actual constructor code you update this to point to the value passed in the constructor.
So something like (pseudo code):
class YourClass:
public:
YourClass(RA8875* pointer) {
_pointer = pointer;
}
void otherFunction(void) {
_pointer->RA8875function();
}
private:
RA8875* _pointer;
}