1

I'm writing a GLFW library wrapper - class named GLFW_Facade. There is RenderLoop function which is mentioned to be a loop in which a rendering function will be executed. I need to pass that rendering function to the RenderLoop. I would like that rendering function can take varying amount of parameters so I made that with template. Code compiles but isn't linking.

At first I was passing a std::function with varying amount of arguments, like so

template <typename... N>
void GLFW_Facade::RenderLoop(std::function<void, N...>& cb, N... params)

then I've created a class-wrapper for std::function with varying arguments named Functor.

template <typename R, typename... Args>
class Functor {
public:
    typedef std::function<R(Args...)> FuncType;
    Functor(FuncType func) : mFunc(func) {}
    Functor& operator()(Args... args) {
        mFunc(args...);
        return *this;
    }
private:
    FuncType mFunc;
};

template <typename... N>
void GLFW_Facade::RenderLoop(Functor<void, N...>& cb, N... params) {
    CheckGLFWWindow();
    while (!glfwWindowShouldClose(m_Window)) {
        cb(params);
        ProcessCloseCondition();
        glfwSwapBuffers(m_Window);
        glfwPollEvents();
    }
}

///usage

Functor<void, int> renderfn(render);
glfw->RenderLoop<int>(renderfn, VAO);

Error LNK2019 reference to a not allowed external symbol "public: void __cdecl GLFW_Facade::RenderLoop(class Functor &,int)" (??$RenderLoop@H@GLFW_Facade@@QEAAXAEAV?$Functor@XH@@H@Z) at function main .../main.obj 1

I was expecting that will be linked out.

0 Answers0