Call a method from a class located in another file without include

Viewed 35

I need to call a first class method from another class located in another file. I can't include "object.h" in "library.h" because it's a library. I see something with std::function and std::bind but I am programming for an Arduino project so I don't have the c++ libraries. To give more context : Library class is reading from a text file to extract line by line some values and each time call the callback.

//libray.h file
class Library
{
public:
    int b;
    void read(void (*callback)())
    {
        //there is a loop here and I need to call the callback each turn;
        //b = some value;
        callback();
    }
};

//object.h file
class Object
{
public:
    int a;
    Library library;
    void Start()
    {
        library.read(&callback); //Error : "no known conversion for argument 2 from 'int (Object::*)()' to 'void (*)()'"
    }

    void callback()
    {
        a = library.b;
    }
};

int main()
{
    Object obj;

    obj.Start();

    return 0;
}
0 Answers
Related