I've written a library (functions declared in a .h file and defined in a .cpp file) and I'd like to call its functions from a main program (main.cpp). A function in the library will run and more than once it needs to notify the main program about things so that the main program can figure out what do -- for instance, it could prompt the user for what to do or handle an error.
I think this is what any non-trivial program does but I don't know how to do it or even what terms to Google for.
I'm afraid you're going to have to be a bit more specific.
Perhaps you should explain the actual specific issue/desire, and then one us can help form a design.
If you have multiple programs communicating with each other, this is called "inter-process communication" (IPC). But in your case, I don't see a need for IPC; it sounds like you just need your main function to have a loop that calls a function from your header. But your title doesn't really match your description.
Thank you for the reply. I'll be more specific. This is only one program so no IPC.
I'm writing something that goes through a directory and lists all the files along with their modified dates and size. So the library function is called and when it finds a file it gets the date and size, then needs to send this information back to the main.cpp so the program can determine what to do.
What I've done that seems to work OK is this: there is a function in my main.cpp named doMessage(message_t msg) - where message_t is a struct I've defined to hold the file information. The library calls this function on each file it finds.
So the main program has to implement a doMessage() function. Is this the correct way of doing it?